FUN is a simple, structured, imperative, dynamic, object-oriented, functional and high-level programming language with JIT compilation, garbage collection and Perl-compatible regular expressions. Wisdom ZHANG built it in 2010 as a scripting language to reuse Pascal resources. FUN grew out of the Nuva language (2006), which in turn evolved from TemplateScript (2005). FUN has run in production for years. Its language lineage underpins commercial software used by customers in more than 130 countries, including Fortune 500 companies such as Microsoft, Intel and IBM, as well as high-end hotels and Michelin- and Black Pearl-rated restaurants.
The FUN described here is the production language by 张卫东 (Wisdom ZHANG) since 2010. Its official home is funlang.org, with source code in the GitHub organization github.com/funlang. Other projects that share the name "fun"/"FUN" are unrelated. Articles about this language may also appear on other platforms; the funlang.org version is the reference. See Which FUN? — official sources.
fun say() ?. 'Hello, fun!'; end fun; // prints: Hello, fun! say(); // lambda / anonymous function var f = a -> a * 2; // prints: 42 ?. f(21);
Borrowed from Ada and adapted for easy typing and reading.
Automatic type conversions when they are needed.
Object-oriented programming built around classes.
Functional style reminiscent of Lisp and JavaScript.
A simple, lightweight reference-counting garbage collector.
Perl-compatible syntax and behavior for real text work.
Arrays, associative arrays, hash tables, dictionaries, or mappings, all in one.
Inline assembly and C interop for high-performance computing.
The parser and runtime fit in a single fun.exe of only about 300 KB, with no external dependencies.
For a detailed tour of the language, read the feature highlights.
Windows
Download, unzip, run fun-install.bat once,
then double-click any .fun script.
Download
FUN runtime library 9.0 (contains the IDE)
The runtime itself (fun.exe) is only about 300 KB; the zip adds the
IDE and 40+ demos.
Linux, macOS Build from source on GitHub.
var f = a -> a * 2; var g = a -> a + 3; // prints: 12 ?. g(f(1+2)+3); // prints: 12 ?. 1+2|f+3|g;
class Number(me) this['#'] = you -> (me + you) * me * you; end class; var $ = Number(2); // custom operator # ?. $ .# 3; // method access via index ?. $[1](3);
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';