Fun Programming Language

The Fun language is small but powerful: from glue code to machine code.

FUN is a structured, dynamic language with functional programming, OOP, GC and PCRE.

Since 2010, Wisdom ZHANG has designed and implemented FUN to reuse Pascal resources. It has been used in real projects ever since. Its predecessor was Nuva (2006), which grew out of TemplateScript (2005). Commercial software written in these languages sells in more than 130 countries, with customers including Microsoft, Intel and IBM, as well as five-star hotels and restaurants with Michelin and Black Pearl ratings.

Which "FUN"? Official sources.

FUN is the language designed and implemented by 张卫东 (Wisdom ZHANG) starting in 2010. Its home is funlang.org; the source code is at github.com/funlang. Other projects called "fun"/"FUN" are unrelated. Articles about FUN may appear on other platforms; the funlang.org version is the reference. See Which FUN? — official sources.

A quick taste

hello.fun
fun say()
  ?. 'Hello, fun!';
end fun;

// prints: Hello, fun!
say();

// lambda / anonymous function
var f = a -> a * 2;

// prints: 42
?. f(21);

Why FUN

Simple, clear syntax

Borrowed from Ada and adapted for easy typing and reading.

Dynamic language

Types are resolved at runtime, and code can be generated at runtime.

Class-based OOP

Object-oriented programming built around classes, with single inheritance.

First-class functions

Functional style reminiscent of Lisp and JavaScript.

Lightweight GC

A simple, lightweight reference-counting garbage collector.

Perl-compatible regex

Perl-compatible syntax and behavior for real text work.

One list type

Arrays, associative arrays, hash tables, dictionaries, or mappings, all in one.

JIT compilation

Inline C and assembly interop for high-performance computing.

Single file

The runtime is a single executable with no external dependencies.

For a detailed tour of the language, read the feature highlights.

Quick start

Windows Download, unzip, run fun-install.bat once, then double-click any .fun script.

Download

FUN runtime library 9.4 (contains the IDE)

The runtime itself (fun.exe) is only about 350 KB; the zip adds the IDE and 40+ demos.

Download fun.zip (~1.1 MB)

Linux & macOS Build the runtime from source; write the UI in HTML, CSS and JavaScript.

Open source

Fun core + fun-ui

The core project includes native build scripts for Linux and macOS. fun-ui is MIT-licensed and adds the browser UI layer on Windows, Linux and macOS.

Features in code

Pipeline & function composition

pipeline.fun
var f = a -> a * 2;
var g = a -> a + 3;

// prints: 12
?. g(f(1+2)+3);

// prints: 12
?. 1+2|f+3|g;

Object-oriented programming & custom operators

number.fun
class Number(me)
  this['#'] = you -> (me + you) * me * you;
end class;

var $ = Number(2);

// custom operator #
?. $ .# 3;

// method access via index
?. $[1](3);

JIT compilation & low-level interaction

jit.fun
use 'lib-jit.fun';

var ii = 0;
fun cb(a, b)
  ii = a * 2^32 + b;
  ?, 'cb'; ?. ii;
  result = ii;
end fun;

var s = `#!asm i:i
    mov ecx, dword ptr [esp+04]
    @sum1ton
    push eax
    push edx
    mov  eax, <test>
    call eax
`;

var jit = NewJit(s, names: [test: cb.@toCallback(nil, 'ii:i', true)]);
?. jit.Run(100000000);
jit.Delete();
?. 'Ok';

Resources