Retroactive documentation for C primitives, boot forms, and type system functions.
litReturn the argument unevaluated (quote).
Parameters:
ANY — Any expressionReturns: ANY — The expression itself
Examples:
(lit x) => 'x
(lit (1 2 3)) => (1 2 3)defBind a name to a value in the current environment.
Value is evaluated before the name is bound. Use the self parameter (first arg to fn) for recursion.
Parameters:
SYMBOL — Name to bindANY — Expression to evaluate and bindExamples:
(def x 42) => 42See also: set!
set!Mutate an existing binding.
Signals an error if name is not already bound.
Parameters:
SYMBOL — Bound name to updateANY — New valueExamples:
(do (def x 1) (set! x 2) x) => 2See also: def
fnCreate a closure (applicative: arguments are evaluated before the body runs).
Parameters:
LIST — Parameter list: (a b), (a . rest), or args for variadicANY — Body expression(s)Returns: PROCEDURE — A new closure
Examples:
(def add (fn (_ a b) (+ a b))) =>
((fn (_ x) (* x x)) 5) => 25See also: op
opCreate an operative (fexpr: arguments are NOT evaluated).
Use eval with the env parameter to evaluate arguments selectively.
Parameters:
LIST — Formal parameters for unevaluated argsSYMBOL — Name bound to caller’s environmentANY — Body expression(s)Returns: OPERATIVE — A new operative
Examples:
(def my-if (op (test then else) e (if (eval test e) (eval then e) (eval else e)))) => See also: fn
evalEvaluate an expression, optionally in a given environment.
With one arg: uses TCO (tail-call safe). With env arg: saves/restores env after.
An environment is one pair, (bindings . parent), not an alist. The engine does not check its shape: a hand-built one, such as (list (pair ‘x 5)), crashes the process.
Parameters:
ANY — Expression to evaluatePAIR — Environment to evaluate in (optional): one an operative receives as its environment parameter, or one (Env current) or (Fn env f) answersReturns: ANY — Result of evaluation
Examples:
(eval '(+ 1 2)) => 3
(let ((k 7)) ((op () e (eval '(+ k 1) e)))) => 8eval!Evaluate in current environment, returning the result immediately.
No TCO, no env save/restore. Use for non-tail evaluation of computed forms.
Parameters:
ANY — Expression to evaluateReturns: ANY — Result of evaluation
Examples:
(eval! '(* 6 7)) => 42See also: eval
matchPattern matching: evaluate clauses until a test succeeds.
Similar to cond but a C primitive. Tests are evaluated in order.
Parameters:
LIST — ((test result) …) pairs — first truthy test winsExamples:
(match ((= x 0) "zero") ((< x 0) "neg") (#t "pos")) => guardError handler: evaluate body with an error guard.
Parameters:
SYMBOL — Name bound to the error valueANY — Expression evaluated if error occurs (var is bound)ANY — Expression to evaluateExamples:
(guard (e (list 'caught e)) (error "boom")) => ('caught "boom")errorSignal an error with a message.
Parameters:
STRING — Error messageANY — Associated value (optional)Examples:
(guard (e e) (error "bad input")) => "bad input"wrapCreate an applicative from a combiner (evaluates args before calling).
Parameters:
CALLABLE — An operative or procedureReturns: CALLABLE — An applicative
Examples:
((wrap (op (a) e a)) (+ 1 2)) => 3unwrapExtract the underlying combiner from an applicative.
Parameters:
CALLABLE — A wrapped combinerReturns: CALLABLE — The underlying combiner
Examples:
((unwrap (wrap (op (a) e a))) (+ 1 2)) => ('+ 1 2)pairCreate a new pair (cons cell) from two values.
Parameters:
ANY — First element (head)ANY — Second element (tail)Returns: PAIR — A new pair
Examples:
(pair 1 2) => (1 . 2)
(pair 1 (pair 2 ())) => (1 2)firstReturn the first element (head) of a pair.
Parameters:
PAIR — A pairReturns: ANY — The first element
Examples:
(first '(1 2 3)) => 1restReturn the second element (tail) of a pair.
Parameters:
PAIR — A pairReturns: ANY — The second element
Examples:
(rest '(1 2 3)) => (2 3)+Variadic addition. Returns the sum of all arguments.
Parameters:
NUMBER — Zero or more numbersReturns: NUMBER — Sum of all arguments, or 0 with no arguments
Examples:
(+ 1 2 3) => 6
(+) => 0-Variadic subtraction. With one argument, negates. With multiple, folds left.
Parameters:
NUMBER — One or more numbersReturns: NUMBER — Difference, or negation with one argument
Examples:
(- 10 3 2) => 5
(- 5) => -5*Variadic multiplication. Returns the product of all arguments.
Parameters:
NUMBER — Zero or more numbersReturns: NUMBER — Product of all arguments, or 1 with no arguments
Examples:
(* 2 3 4) => 24
(*) => 1/Variadic integer division. Folds left.
Parameters:
NUMBER — One or more numbersReturns: NUMBER — Quotient from left fold
Examples:
(/ 100 5 2) => 10%Variadic modulo. Folds left.
Parameters:
NUMBER — Two or more numbersReturns: NUMBER — Remainder from left fold
Examples:
(% 10 3) => 1~Bitwise NOT.
Parameters:
INTEGER — IntegerReturns: INTEGER — Bitwise complement
Examples:
(~ 0) => -1
(~ 5) => -6&Bitwise AND.
Parameters:
INTEGER — First operandINTEGER — Second operandReturns: INTEGER — Bitwise AND
Examples:
(& 12 10) => 8|Bitwise OR.
Parameters:
INTEGER — First operandINTEGER — Second operandReturns: INTEGER — Bitwise OR
Examples:
(| 12 10) => 14^Bitwise XOR.
Parameters:
INTEGER — First operandINTEGER — Second operandReturns: INTEGER — Bitwise XOR
Examples:
(^ 12 10) => 6<<Left shift.
Parameters:
INTEGER — Value to shiftINTEGER — Number of bitsReturns: INTEGER — Shifted value
Examples:
(<< 1 4) => 16>>Arithmetic right shift.
Parameters:
INTEGER — Value to shiftINTEGER — Number of bitsReturns: INTEGER — Shifted value
Examples:
(>> 16 2) => 4
(>> -16 2) => -4eq?Compare the value words of a and b: #t when the two hold the same word. An integer, a character or a symbol compares by its value; any other object by its first data word, so two distinct pairs whose first elements are the same object answer #t, as do an integer and the character with that code. Use same? for object identity.
Parameters:
ANY — First valueANY — Second valueReturns: BOOL — #t when the value words are the same
Examples:
(eq? 'x 'x) => #t
(eq? (pair 'x 1) (pair 'x 9)) => #t
(same? (pair 'x 1) (pair 'x 9)) => #fSee also: same?
same?Test object identity: #t when a and b are the same object. Values that are equal but made separately are not: two integer literals with one value, or two strings with one text, answer #f. nil, #t and #f are each a single object.
Parameters:
ANY — First valueANY — Second valueReturns: BOOL — #t when a and b are the same object
Examples:
(let ((p (pair 'x 1))) (same? p p)) => #t
(same? (pair 'x 1) (pair 'x 9)) => #f
(same? 7 7) => #f
(same? () ()) => #tSee also: eq?
=Test numeric equality.
Parameters:
INTEGER — First numberINTEGER — Second numberReturns: BOOL — t if equal
Examples:
(= 3 3) => #t
(= 3 4) => #f<Test numeric less-than.
Parameters:
INTEGER — First numberINTEGER — Second numberReturns: BOOL — t if a < b
Examples:
(< 1 2) => #t
(< 2 1) => #fsymbol->strConvert a symbol to a string.
Parameters:
SYMBOL — A symbolReturns: STRING — The symbol’s name
Examples:
(symbol->str 'abc) => "abc"bytes->strPack a list of characters into a string, one low byte per char.
Parameters:
LIST — List of byte-valued charactersReturns: STRING — A string of those bytes
Examples:
(bytes->str (list #\h #\i)) => "hi"writeWrite a value in machine-readable form.
Strings are quoted, characters show read syntax. Use for serialization.
Parameters:
ANY — Value to writeSee also: display
displayDisplay a value in human-readable form.
Strings are unquoted, characters are bare. Use for user output.
Parameters:
ANY — Value to displaySee also: write
alloc-limit!Set the allocation ceiling (runaway-memory guard): the process stops rather than allocate past n objects. 0 disables.
Parameters:
INTEGER — Object-count ceiling; 0 = unlimitedcall/ccCall a function with the current continuation.
Parameters:
CALLABLE — Function receiving the continuationReturns: ANY — Result of f, or value passed to continuation
Examples:
(+ 1 (call/cc (fn (_ k) (k 41)))) => 42
(+ 1 (call/cc (fn (_ k) 2))) => 3null?Test if a value is nil (the empty list).
Parameters:
ANY — Value to testReturns: BOOL — t if nil
Examples:
(null? ()) => #t
(null? '(1)) => #fpair?Test if a value is a pair (cons cell).
Parameters:
ANY — Value to testReturns: BOOL — t if pair
Examples:
(pair? '(1)) => #t
(pair? ()) => #fatom?Test if a value is an atom (not a pair).
Parameters:
ANY — Value to testReturns: BOOL — t if not a pair
Examples:
(atom? 5) => #t
(atom? '(1)) => #fnumber?Test if a value is an integer.
Parameters:
ANY — Value to testReturns: BOOL — t if integer
Examples:
(number? 42) => #t
(number? "42") => #freal?Test if a value is a real number: a number that is not complex. The number modules extend it in place as they load.
Parameters:
ANY — Value to testReturns: BOOL — t if real
Examples:
(real? 42) => #t
(real? 'a) => #fstr?Test if a value is a string.
Parameters:
ANY — Value to testReturns: BOOL — t if string
Examples:
(str? "a") => #t
(str? 'a) => #fsymbol?Test if a value is a symbol.
Parameters:
ANY — Value to testReturns: BOOL — t if symbol
Examples:
(symbol? 'a) => #t
(symbol? "a") => #fchar?Test if a value is a character.
Parameters:
ANY — Value to testReturns: BOOL — t if character
Examples:
(char? #\a) => #t
(char? "a") => #fprocedure?Test if a value is callable (procedure or primitive).
Parameters:
ANY — Value to testReturns: BOOL — t if procedure or primitive
Examples:
(procedure? list) => #t
(procedure? 'list) => #fifConditional: evaluate test, then branch.
Parameters:
ANY — Condition expressionANY — True branchANY — False branch (optional)Examples:
(if (> 3 2) "yes" "no") => "yes"letBind local variables and evaluate body.
Named let: (let name ((var init) …) body) creates a loop.
Parameters:
LIST — ((name value) …) binding pairsANY — Body expressionExamples:
(let ((x 1) (y 2)) (+ x y)) => 3
(let loop ((n 5) (acc 1)) (if (= n 0) acc (loop (- n 1) (* acc n)))) => 120See also: letrec
doEvaluate expressions sequentially, return last result.
Parameters:
ANY — One or more expressionsExamples:
(do (def x 1) (+ x 1)) => 2beginAlias for do.
Examples:
(begin 1 2) => 2See also: do
notLogical negation.
Parameters:
ANY — Value to negateReturns: BOOL — t if x is falsy
Examples:
(not #f) => #t
(not 0) => #flistCreate a list from arguments.
Parameters:
ANY — Zero or more valuesReturns: LIST — A new list
Examples:
(list 1 2 3) => (1 2 3)andShort-circuit logical AND.
Parameters:
ANY — Zero or more expressionsReturns: ANY — Last truthy value, or #f
Examples:
(and 1 2 3) => 3orShort-circuit logical OR.
Parameters:
ANY — Zero or more expressionsReturns: ANY — First truthy value, or nil
Examples:
(or #f 42) => 42newlineDisplay a newline character.
quasiQuasiquote: template with unquote and splicing.
Use , to unquote a single expression, ,@ to splice a list.
Parameters:
ANY — Template expression with , and ,@ escapesExamples:
(let ((x 42)) (quasi (a ,x b))) => ('a 42 'b)replStart the read-eval-print loop.
Customizable: %repl-prompt and %repl-print control display.
include-onceLoad and evaluate a file, skipping if already loaded.
Parameters:
STRING — File path to includeprovideRegister a module’s exported symbols.
Parameters:
SYMBOL — Module name, e.g. x/listSYMBOL — Exported symbol names (variadic)importImport a module (include its file if not yet loaded).
Parameters:
SYMBOL — Module name to importstr=?Test string equality.
Parameters:
STRING — First stringSTRING — Second stringReturns: BOOL — t if equal
Examples:
(str=? "abc" "abc") => #t
(str=? "abc" "abd") => #frequire-onceInclude a file only if it has not been loaded before. Alias for include-once.
Parameters:
STRING — File path to includeSee also: include-once
docAttach documentation metadata to a definition, provide, or bare symbol.
Three forms: (doc (def name val) meta… desc), (doc (provide name syms) meta… desc), (doc name meta… desc)
Meta forms: (param name TYPE desc), (returns TYPE desc), (example expr result), (see name), (note text)
noteSection marker for documentation grouping. No-op at runtime.
Parameters:
STRING — Section descriptionhelpLook up documentation in the REPL.
(help) shows overview. (help name) shows function, class or module docs; (help Class member) shows one member. (help modules) lists all modules.
A name is a bare symbol as written, or an expression that evaluates to one, such as ‘name. Anything else answers “No documentation”. A class listing leaves out members whose names begin with %; (help Class %member) still answers for one by name.
aproposSearch documentation by name substring, printing each match with its description.
Parameters:
STRING — Substring to search for: a string, a bare symbol, or an expression that evaluates to oneReturns: LIST — The matching names, as symbols, sorted by name; () when nothing matches
modulesList all known modules with load status and descriptions.
primsThe primitives catalogue: an alist of (ns . ((method . impl) …)) domains.
The registry of stable implementation identities; modules fetch dependencies
from it at load instead of assuming ambient global names.
Returns: LIST — The live catalogue alist
Examples:
(pair? (prims)) => #tSee also: prim-ref
prim-domainThe method alist filed under a catalogue namespace, or nil.
Parameters:
SYMBOL — Namespace symbol, e.g. ‘intReturns: LIST — ((method . impl) …) for the namespace, or nil
Examples:
(pair? (prim-domain 'int)) => #t
(null? (prim-domain 'no-such-ns)) => #tSee also: prims
prim-refFetch the implementation filed under ns/method, or nil.
The consumer half of the registry protocol. Fetch at module load and
cache in a lexical (hot paths) or call inline (cold paths).
Parameters:
SYMBOL — Namespace symbol, e.g. ‘iterSYMBOL — Method symbol, e.g. ‘nextReturns: ANY — The registered implementation, or nil if absent
Examples:
(prim-ref 'int '+) => #<prim>See also: prim-reg!
prim-reg!File an x-lang value into the catalogue under ns/method.
The producer half of the registry protocol: library implementations register
under the same stable identities as C prims. Registration prepends, so a
re-registration shadows the older entry on lookup. Returns nil.
Parameters:
SYMBOL — Namespace symbol, e.g. ‘floatSYMBOL — Method symbol, e.g. ‘+ANY — The implementation to register (fn, op, or any value)Examples:
(do (prim-reg! 'demo 'twice (fn (_ n) (* n 2))) ((prim-ref 'demo 'twice) 21)) => 42See also: prim-ref
x/core/predicatesType predicates (null?, pair?, number?, real?, str?, symbol?, char?, …) built from C primitives.
Examples:
(list (null? ()) (pair? ()) (symbol? 'a)) => (#t #f #t)x/core/controlCore control flow: if and let, as operatives built on match.
Examples:
(let ((n 3)) (if (> n 2) 'big 'small)) => 'big