S-exp GPU
All pages
Docs · The languageMarkdown

Builtins

Every builtin function, evaluated at compile time. Tensor operations are in tensor operations; prelude macros and functions written in Lisp are in the prelude. Builtins need no require and can be shadowed.

Arithmetic and comparison

namesnotes
+ - * /n-ary; / always returns a float, so (/ 1 2) is 0.5 and a head dimension is (floor (/ dim heads))
modthe remainder that is never negative, so (mod -7 3) and (mod -7 -3) are both 2; numbers, or tensors as mod states
pow sqrt exp log floorfloor returns an integer; a float outside -2^63 to 2^63 - 1 is E-EVAL-007
minnumbers, or the smallest element of a tensor; the elementwise minimum is minimum
maxnumbers, or the largest element of a tensor; the elementwise maximum is maximum
= /= < <= > >=numeric; /= requires pairwise distinct arguments
eq equalidentity, and structural equality for data; use equal for lists, strings, keywords
not truthy(truthy x) is true unless x is nil or false

+ - * / mod pow sqrt exp log min max and the six comparisons also take tensors; see tensor operations. Integer overflow and division by a zero number are E-EVAL-007; a float tensor divided by zero holds NaN.

Lists and higher order

builtinresult
(list x...)a list
(cons x list)a new list with x in front; there are no dotted pairs
(first xs) (rest xs)the first element or nil, and the rest as a list
(nth i xs)the i-th element, nil past the end
(length xs)elements of a list or vector, characters of a string
(append xs...)one list
(reverse xs)a list
(vector x...)a vector; [x ...] is the literal
(vec xs) (to-list xs)a vector from a list, a list from a vector
(map f xs)a list of (f x); one sequence only
(filter f xs)the elements where (f x) is true
(reduce f init xs)a left fold, (f (f init x0) x1)...
(repeat n f)(list (f 0) ... (f (- n 1)))
(range n) (range a b)integers from 0 or a below n or b
(apply f arg... list)see functions

Sequence builtins accept a list or a vector and return a list. nil is the empty list. Lists are immutable.

Plists

builtinresult
(plist :k v ...)a property list; keys must be keywords and come in pairs
(getf plist key [default])the value after the first equal key, else default or nil

prepare's return value and curriculum observations are plists. Read ctx fields with getf. (replace plist :key value ...) constructs a new plist, preserving existing field order and appending newly introduced fields; it never mutates the original.

Multiple values

values and values-list; the binding forms are special forms, see multiple values. top-k returns its values and their positions as two values (tensor operations).

Text and symbols

builtinresult
(str x...)the printed forms concatenated into one string
(format "~a~%" x...)a string; understands ~a and ~% only
(symbol-name s)the printable name of a symbol or keyword, a string
(keyword x)a keyword from a symbol, string or keyword
(gensym [prefix])a fresh symbol; see macros
(symbol-prefix-p "g!" s)whether a symbol's name starts with the prefix

intern is a special form; see macros.

Predicates

consp (a non-empty list), listp (a list or nil), vectorp, null, numberp, keywordp, symbolp, stringp, and functionp (a function, builtin, model, model constructor or optimizer definition).

Errors

(error message...) is E-EVAL-001; (assert test [message]) is E-EVAL-002. See control.

Experiment constructors

Ordinary builtins that build configuration values:

builtinpage
loader stage files manifest fieldloaders
select select-not select-and groupoptimizer groups
namedmodels
optimizer-updatewriting optimizers
metric diagnostic tap-gradient objective-term countermetrics, writing diagnostics, loaders
recordevaluation
guard assert-finiteguards

field also reads a batch inside prepare: (field batch :tokens).

Related: the prelude, tensor operations.