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))
mod pow sqrt exp log floorfloor returns an integer
minnumbers only
maxnumbers, or the maximum of a tensor
= /= < <= > >=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

+ - * / pow sqrt exp log max and the six comparisons are overloaded: the tensor reading wins when any argument is a tensor. Integer overflow and division by zero are E-EVAL-007.

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

ctx, prepare's return value and curriculum observations are plists.

Multiple values

values and values-list; the binding forms are special forms, see multiple values.

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 countermetrics, writing diagnostics, loaders

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

Related: the prelude, tensor operations.