standard library
mu documentation
Every name a mu program can call, in the three layers it can call them from. Press / to search, or run mu-doc in a terminal for the same documentation offline.
Host builtins all 28 →
Provided by whichever host runs the program — Go in the Go host, mu in the self-hosted one — rather than by mu library code. Always in scope, and deliberately few: a capability lands here only when mu cannot express it.
| append | append(list_or_buffer, value) returns a new list or buffer with value appended. |
| args | args() returns the process argument list. |
| buf | buf(size) allocates a mutable byte buffer of the given size. |
| chan | chan(capacity) creates a channel with the given buffer capacity. |
| chr | chr(codepoint) converts a Unicode codepoint to a string character. |
| del | del(collection, index_or_key) removes a list element, buffer byte, or map entry. |
| dlcall | dlcall(fn, args...) calls a foreign function pointer (FFI). |
| dlopen | dlopen(path) opens a shared library and returns a handle (FFI). |
| dlsym | dlsym(lib, symbol) resolves a symbol in a shared library (FFI). |
| env | env() returns a map of environment variables; env(key) returns a string or nil. |
| error | error(message) returns an error value with the given message. |
| help | help() shows general Mu help. |
| inspect | inspect(value) returns a human-readable string representation. |
| keys | keys(map) returns a list of keys in a map. |
| len | len(value) returns the length of a string, list, map, or buffer. |
| ord | ord(char) returns the code point of a one-character string: a one-byte string gives its byte value, and a 2-4 byte string is decoded as one UTF-8 sequence. |
| platform | platform() returns the current target as an "os/arch" string, e.g. "linux/amd64". |
| poll | poll(channel, timeout_ms?) receives without blocking — or waits up to timeout_ms — answering [ok, value]. |
| pop | pop(list_or_buffer) removes and returns the last element or byte. |
| push | push(channel, value) sends without blocking, reporting whether there was room. |
| recv | recv(channel) receives a value, blocking while the channel is empty. |
| send | send(channel, value) sends a value, blocking while the buffer is full. |
| str | str(value) converts value to a string. |
| syscall | syscall(name_or_number, args...) performs a raw OS syscall. |
| task | task(fn) starts fn as a concurrent task and returns a handle to wait on. |
| traceback | traceback() renders the current call stack; traceback(err) renders where err was created. |
| type | type(value) returns the runtime type tag (e.g. "STRING"). |
| wait | wait(task) blocks until the task finishes and returns its result. |
Prelude all 13 →
Written in mu (lib/builtins.mu), always in scope, never imported.
| bool | bool(value) converts a value to a boolean. |
| exit | exit exits the process with the given status code. |
| has | has(m, key) reports whether the map contains the key. |
| input | input reads a single line from stdin. |
| insert | insert(coll, index, value) inserts value at index, shifting the tail up. |
| int | int(value) coerces a value to an integer. |
| is_error | is_error reports whether the value is an ERROR value. |
| must | must yields the value, or panics when it is an ERROR. |
| panic | panic writes a panic message and a traceback to stderr and exits (or raises a test failure). |
| print writes its arguments to stdout separated by spaces and followed by a newline. | |
| test | test registers a test case and runs it when selected by MU_TEST_RUN. |
| try | try binds name to the value of expr and propagates an ERROR out of the enclosing function. |
| values | values(m) returns the map's values, in the same order as keys(m). |
Modules
Written in mu and reached behind a namespace: import "strings", then strings.split(s, ",").
assert.mu keeps the core assertion helpers used by the lib tests and tooling so callers can document invariants and fail fast when expectations are violated.
decimal provides a decimal type with fixed-point arithmetic.
embed provides compile-time asset embedding.
encoding provides tiny helpers for serializing binary data at the syscall layer.
errno maps raw errno integers to symbolic names and human-friendly messages.
ffi provides helpers for binding foreign functions.
flag parses command-line arguments.
fp provides high-level functions for functional programming.
hashmap provides a hash map (associative array) implemented purely in mu.
http provides minimal HTTP/1.1 helpers for parsing, formatting, routing, serving, and making plain-text client requests over lib/sockets.
io is the file and descriptor API.
iter provides lazy, pull-driven iterators built on Mu tasks and channels.
json provides a collection of JSON encoding and decoding functions.
macro is the compile-time macro surface: define registers a handler that rewrites its call site during expansion, and requires declares which build-machine capabilities that module's handlers are allowed to reach.
math provides a collection of mathematical functions.
objc provides access to the Objective-C runtime on macOS: classes, selectors, message sends, and — through NSInvocation — methods whose signatures the integer-only FFI cannot express directly.
path is a collection of path manipulation functions.
process is a collection of process-related functions.
rand provides a small pseudo-random number generator.
result provides helpers for the standardized result.Result shape so callers can reason about fallible helpers without checking type(...).
sha256 — the SHA-256 cryptographic hash (FIPS 180-4), pure mu.
shape provides helpers for tagged map values.
sockets provides minimal socket helpers built directly on raw syscalls.
sqlite provides minimal SQLite bindings via the FFI.
strings provides a collection of string manipulation functions.
text provides a collection of text manipulation functions.
time provides helpers for time-related operations.
turtle provides simple Logo-style turtle graphics using SDL2.
typing provides utilities for type checking.
ui is a minimal native GUI toolkit: windows, labels, buttons, text inputs, checkboxes, multi-line textareas and repeating timers, laid out in pixels from the top-left corner and driven by an event loop that dispatches to µ closures.
ui_cocoa is the macOS backend behind ui: widgets are real AppKit controls reached through objc, and the event loop pumps NSApplication while draining the action queue Cocoa fills.
ui_x11 is the Linux backend behind ui: widgets drawn by µ itself with the X11 core protocol — rectangles and server-side "fixed"-font text — and an event loop over x11.wait_event.
x11 speaks the X11 wire protocol directly: connect, authenticate, create windows, draw, and read events — over a unix socket, in pure µ.
Shared helpers
Importable, but not meant to be imported directly: these exist to be shared between a module and the backend under it.
| sockets_helpers | sockets_helpers provides shared parsing buffers, address utilities, and runtime helpers for lib/sockets.mu. |