fun> About
More information about having fun... :)
Table of contents
What is Fun?
Fun is a small, strict, and simple programming language that runs on a compact stack-based virtual machine. The C core is intentionally minimal; most functionality and standard libraries are implemented in Fun itself.
Fun is dynamically typed with optional static type annotations, featuring first-class functions, classes with inheritance, pattern matching, and a rich standard library. It supports everything from basic scripting to TCP sockets, serial communication, threading, cryptography (MD5, SHA-1/256/384/512, CRC-32, AES-256), and a built-in debugger.
Influenced by: Bash, C, Lua, PHP, Python, and Rust.
Fun is an experiment - just for fun - but Fun works!
Fun is and will ever be 100% free under the terms of the Apache-2.0 License.
Idea
- Simplicity
- Consistency
- Simple to extend
- Hackable
- Joy in coding
- Fun!
Characteristics
- Dynamic typing with optional static type annotations (
number,string,boolean,float,byte,uint8–uint64,int8–int64) - Stack-based bytecode VM written in C99 with ~220 opcodes
- First-class functions, anonymous functions (
fn), and higher-order operations (map,filter,reduce) - Classes with constructors, methods, and single inheritance
- Exception handling with
try/catch/finally - Built-in data structures: arrays (with slicing), maps/objects, strings
- Concurrency: threads (
thread_spawn,thread_join) and cooperative async scheduler - Networking: TCP and Unix domain sockets with non-blocking I/O polling
- Serial communication: full termios-based serial port control
- Cryptography: pure-Fun implementations of MD5, SHA-1/256/384/512, CRC-32/CRC-32C, AES-256 ECB
- Built-in debugger with breakpoints, step/next/finish, and stack inspection
- Minimal C core — most standard libraries are implemented in Fun itself
- Internal style:
snake_casefor functions and variables,CamelCasefor class names
The Fun Manifesto
Fun is a programming language built on a simple idea: Coding should be enjoyable, elegant, and consistent.
Philosophy
- Fun is Fun
Programming should spark creativity, not frustration. Code in Fun feels light, playful, and rewarding. - Fun Uses Nothing
Minimalism is power. No unnecessary features, no endless syntax variations, no formatting debates. Just clean, uniform code. - Indentation is Truth
Two spaces, always. No tabs, no four-space wars. Code should look the same everywhere, from your laptop to /usr/bin/fun. - One Way to Do It
No clutter, no 15 ways of writing the same thing. Simplicity means clarity. - Hackable by Nature
Fun should be small and embeddable, like Lua. Easy to understand, extend, and tinker with — true to the hacker spirit. - Beautiful Defaults
A language that doesn’t need linters, formatters, or style guides. Beauty is built in.
The Community
Fun is not about being the fastest or the most feature-rich. It’s about sharing joy in coding. The community should be:
- Respectful
- Curious
- Creative
Like the name says: Fun Unites Nerds.
Use the Fun Community Page to get in touch.
The Goal
A language that feels like home for developers who:
- Love minimal, elegant tools
- Believe consistency is freedom
- Want to write code that looks good and feels good
Fun may not change the world — but it will make programming a little more fun.
Language Features
Core Syntax & Types
- Indentation-based blocks (2-space)
- Line and block comments
- Static type annotations with automatic runtime range clamping for fixed-width integers
typeof(),to_string(),to_number(),cast()— type introspection and conversionexitstatement with optional exit code- Source file includes:
#include "path"and#include <path>
Operators
- Arithmetic:
+,-,*,/,% - Comparison:
<,<=,>,>=,==,!= - Logical:
&&,||,!(short-circuit) - Bitwise:
band(),bor(),bxor(),bnot(),shl(),shr(),rol(),ror() - Ternary:
condition ? true_expr : false_expr
Control Flow
if/else if/elsewhilewithbreakandcontinuefor var in array— iterationfor var in range(start, end)— numeric rangefor (key, value) in map— map destructuringmatchexpression (stdlib)try/catch/finally
Functions
fun name(params) body— named functionsfn(params) body— anonymous function literals- First-class: pass as arguments, store in variables
- Recursion support
returnwith optional value (implicit nil)
Object-Oriented Programming
class Name(typed params) body— class definition_construct(this, ...)— auto-invoked constructorthiskeyword for instance accessobj.method(args)— method call sugar (auto-binds this)obj.field— dot property accessclass Child(...) extends Parent— inheritance with method overriding
Data Structures
- Arrays: literal
[1, 2, 3], index accessarr[0], slicearr[1:3], negative indices,len(),push(),pop(),insert(),remove(),contains(),indexOf(),clear(),enumerate(),zip(),join(),map(),filter(),reduce() - Maps: literal
{"key": value}, bracket accessmap["key"], dot accessmap.key,has(),keys(),values() - Strings: concatenation with
+,len(),substr(),find(),split(),join()
Pattern Matching & Regex
- POSIX regex:
regex_match(),regex_search(),regex_replace()
Mathematics
- Built-in:
abs,min,max,fmin,fmax,clamp,pow,sqrt,floor,ceil,trunc,round,sin,cos,tan,exp,log,log10,gcd,lcm,isqrt,sign - Random:
random_seed(),random_int(),random_number()(cryptographic) - Integer clamping:
sclamp(),uclamp()
I/O & Platform
print(),echo()— outputread_file(),write_file()— file I/Oinput_line()— stdin with optional promptenv(),env_all()— environment variablesproc_run(),system()— process executionos_list_dir()— directory listing
Date, Time & Sleep
time_now_ms(),clock_mono_ms(),date_format(),sleep()
Networking (Built-in, Unix)
- TCP: listen, accept, connect, send, recv, close
- Unix domain sockets: listen, connect
- Non-blocking I/O:
fd_set_nonblock(),fd_poll_read(),fd_poll_write()
Serial Communication (Unix)
serial_open(),serial_config(),serial_send(),serial_recv(),serial_close()
Concurrency
thread_spawn(fn, args)— spawn thread, returns IDthread_join(id)— join, returns result- Cooperative async scheduler in stdlib
Debugging
- Built-in debugger with 64 breakpoints
- Step, next, finish, continue modes
--trace/-tfor opcode-level execution tracing--repl-on-error: enter REPL on runtime error with stack preserved
Standard Library (stdlib)
Written primarily in Fun itself (lib/):
- String utilities: trim, starts/ends-with, split, replace-all, case conversion, repeat
- Array utilities: slice, reverse, concat, unique, flatten
- Math helpers:
abs,clamp,gcd,lcm,powi, min3, max3, array min/max - Hex encoding: hex-to-bytes, bytes-to-hex, dec-to-hex, hex-to-dec
- Base64 encoding: encode/decode
- Cryptography (pure Fun): MD5, SHA-1, SHA-256, SHA-384, SHA-512, CRC-32, CRC-32C, AES-256 ECB
- Functional utilities: Option type (Some/None), Result type (Ok/Err), pattern matching
- Range utilities:
range(n),range2(start, end),range3(start, end, step) - Date/Time:
DateTimeclass with formatting, timers, sleep - CLI:
argv(),parse_args()with flag support - Console:
Consoleclass with prompt, ask, hidden input, progress bar - Process:
Processclass wrapping proc_run/system - Thread:
Threadclass wrapping spawn/join - Socket classes:
TcpClient,TcpServer,UnixClient - Serial:
Serialclass - Async scheduler: cooperative multitasking with I/O polling
- HTTP Servers: static file server, CGI-capable server
- IRC:
IRCClientwith full protocol support - CGI:
CGIclass for web applications
Optional Extensions (Build-time)
Enabled via CMake flags, each wrapping a mature C library:
- JSON (
FUN_WITH_JSON/ json-c) — parse, stringify, file I/O ☑ - cURL (
FUN_WITH_CURL/ libcurl) — HTTP GET, POST, download ☑ - SQLite (
FUN_WITH_SQLITE/ libsqlite3) — open, query, exec, close ☑ - PCRE2 (
FUN_WITH_PCRE2/ libpcre2) — Perl-compatible regex with flags ☑ - OpenSSL (
FUN_WITH_OPENSSL/ libcrypto) — MD5, SHA-256, SHA-512, RIPEMD-160 hashing ☑ - INI (
FUN_WITH_INI/ iniparser) — load, get/set, save config files ☑ - XML (
FUN_WITH_XML2/ libxml2) — parse, navigate, query XML documents ☑ - PC/SC (
FUN_WITH_PCSC/ libpcsclite) — smart card communication ☑ - KCGI (
FUN_WITH_KCGI/ libkcgi) — CGI web applications ☑ - Redis/Valkey (
FUN_WITH_REDIS/ hiredis) — Redis and Valkey support ☑
☑ = Done
Each extension also has a corresponding stdlib wrapper class (e.g., JSON, INI, XML, PCSC, PCRE2, KCGI).
Tooling
fun— Interpreter/REPL: runs.funscripts or starts interactive REPLfunstx— Syntax checker with optional--fixmode- REPL — Full-featured interactive shell with history, tab completion, multi-line input, and commands (
:help,:load,:edit,:save,:debug,:trace,:type, and more) - Built-in debugger — breakpoints, step/next/finish, stack traces
- Formatting —
clang-formattarget for consistent C source
Build System
- CMake 3.10+ with C99 standard
- Build toggles for debug mode, musl, REPL, C++ FFI, Rust FFI, Doxygen docs
- Per-extension toggles for all optional libraries
- Release builds with LTO, section GC, and symbol stripping
- CTest integration — example scripts run as automated tests
- Doxygen API reference generation

