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 valueSee 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
applyApply a function to a list of arguments.
Parameters:
CALLABLE — Function to applyLIST — Argument listReturns: ANY — Result of application
Examples:
(apply + '(1 2)) => 3evalEvaluate an expression, optionally in a given environment.
With one arg: uses TCO (tail-call safe). With env arg: saves/restores env after.
Parameters:
ANY — Expression to evaluateLIST — Environment alist (optional)Returns: ANY — Result of evaluation
See also: eval!
eval!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
See 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
unwrapExtract the underlying combiner from an applicative.
Parameters:
CALLABLE — A wrapped combinerReturns: CALLABLE — The underlying combiner
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)set-first!Mutate the first element of a pair.
Parameters:
PAIR — A pairANY — New valueset-rest!Mutate the second element of a pair.
Parameters:
PAIR — A pairANY — New valuefirst-intReturn the first element as a raw integer.
Parameters:
PAIR — A pairrest-intReturn the second element as a raw integer.
Parameters:
PAIR — A pairset-first-int!Mutate the first element as a raw integer.
Parameters:
PAIR — A pairINT — Integer valueset-rest-int!Mutate the second element as a raw integer.
Parameters:
PAIR — A pairINT — Integer value+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:
INT — IntegerReturns: INT — Bitwise complement
&Bitwise AND.
Parameters:
INT — First operandINT — Second operandReturns: INT — Bitwise AND
|Bitwise OR.
Parameters:
INT — First operandINT — Second operandReturns: INT — Bitwise OR
^Bitwise XOR.
Parameters:
INT — First operandINT — Second operandReturns: INT — Bitwise XOR
<<Left shift.
Parameters:
INT — Value to shiftINT — Number of bitsReturns: INT — Shifted value
>>Arithmetic right shift.
Parameters:
INT — Value to shiftINT — Number of bitsReturns: INT — Shifted value
eq?Test identity equality (pointer equality for objects, value for atoms).
Parameters:
ANY — First valueANY — Second valueReturns: BOOL — t if identical
=Test numeric equality.
Parameters:
INT — First numberINT — Second numberReturns: BOOL — t if equal
<Test numeric less-than.
Parameters:
INT — First numberINT — Second numberReturns: BOOL — t if a < b
symbol->strConvert a symbol to a string.
Parameters:
SYMBOL — A symbolReturns: STRING — The symbol’s name
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
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:
INT — 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
null?Test if a value is nil (the empty list).
Parameters:
ANY — Value to testReturns: BOOL — t if nil
pair?Test if a value is a pair (cons cell).
Parameters:
ANY — Value to testReturns: BOOL — t if pair
atom?Test if a value is an atom (not a pair).
Parameters:
ANY — Value to testReturns: BOOL — t if not a pair
number?Test if a value is an integer.
Parameters:
ANY — Value to testReturns: BOOL — t if integer
str?Test if a value is a string.
Parameters:
ANY — Value to testReturns: BOOL — t if string
symbol?Test if a value is a symbol.
Parameters:
ANY — Value to testReturns: BOOL — t if symbol
char?Test if a value is a character.
Parameters:
ANY — Value to testReturns: BOOL — t if character
procedure?Test if a value is callable (procedure or primitive).
Parameters:
ANY — Value to testReturns: BOOL — t if procedure or primitive
ifConditional: 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.
See also: do
notLogical negation.
Parameters:
ANY — Value to negateReturns: BOOL — t if x is falsy
listCreate 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 importnumber->strConvert an integer to a string.
Parameters:
INT — Integer to convertINT — Base (optional, default 10)Returns: STRING — String representation
str->numberParse a string as an integer.
Parameters:
STRING — String to parseReturns: INT — Parsed integer, or nil on failure
str-refReturn the character at an index in a string.
Parameters:
STRING — A stringINT — Zero-based indexReturns: CHAR — Character at index
str-lengthReturn the length of a string.
Parameters:
STRING — A stringReturns: INT — Number of characters
substringExtract a substring.
Parameters:
STRING — Source stringINT — Start index (inclusive)INT — End index (exclusive)Returns: STRING — The substring
str=?Test string equality.
Parameters:
STRING — First stringSTRING — Second stringReturns: BOOL — t if equal
require-onceInclude a file only if it has not been loaded before. Alias for include-once.
Parameters:
STRING — File path to includeSee also: include-once
peek-charReturn the next character from stdin without consuming it.
Returns: CHAR — The next character, or () at EOF
current-lineReturn the current source line number.
Returns: INT — Line number in the current input
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 or module docs. (help modules) lists all modules.
aproposSearch documentation by name substring.
Parameters:
STRING — Substring to search formodulesList all known modules with load status and descriptions.
primsThe primitives catalog: 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 catalog alist
See also: prim-ref
prim-domainThe method alist filed under a catalog namespace, or nil.
Parameters:
SYMBOL — Namespace symbol, e.g. ‘intReturns: LIST — ((method . impl) …) for the namespace, or nil
See 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 catalog 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?, str?, symbol?, char?, …) built from C primitives.
x/core/controlCore control flow: if and let, as operatives built on match.