builtins
builtins
module reference
builtin operators and constants.
index
- Cast to !-stream.
- Thread first macro.
- Thread last macro.
- Assert expression is constant.
- A `bang` value-constant.
- Declare symbols in current scope.
- Define a function.
- Evaluate multiple expressions in a new scope.
- Print documentation in console.
- Evaluate definitions in a new scope and return it.
- Export specific symbol definitions as a module/scope.
- The boolean constant `false`.
- Declare a function.
- Make an evaltime const choice.
- Require and define modules.
- Require and use modules.
- Loop on arbitrary data via recursion.
- Merge !-streams.
- Construct an array.
- Construct an struct.
- Print string values.
- Reenter the innermost loop.
- Load a module.
- Switch between multiple inputs.
- Switch between multiple inputs based on normalized i.
- Trace an expression's values at runtime.
- Trace an expression's value at evaltime.
- The boolean constant `true`.
- Merge scopes into current scope.
- Make an evaltime const choice with side effects
- Cast to ~-stream.
details
- Cast to !-stream.
(! val)
(! sig trig)
Casts anything to a !-stream depending on arguments:
- if
val
is a ~-stream, emits events on changes. - if
val
is a !-stream, emits a bang for each incoming event. - if
trig
is given, samplessig
as a new event whentrig
arrives.
- if
- Thread first macro.
(-> initial [expr1 expr2…])
Evaluate expressions
expr1
,expr2
, … while passing the result of the previous expression to the following one, starting withinitial
. The value is always inserted as the first argument. - Thread last macro.
(->> initial [expr1 expr2…])
Evaluate expressions
expr1
,expr2
, … while passing the result of the previous expression to the following one, starting withinitial
. The value is always inserted as the last argument. - Assert expression is constant.
(= val)
Asserts that
val
is a constant expression and returns it. - A `bang` value-constant.
- Declare symbols in current scope.
(def sym1 val-expr1 [sym2 val-expr2…])
Define the symbols
sym1
,sym2
, … to resolve to the values ofval-expr1
,val-expr2
, …. - Define a function.
(defn name-sym (p1 [p2…]) body-expr)
Declare a function and define it as
name-sym
in the current scope. The symbolsp1
,p2
, … will resolve to the arguments passed when the function is invoked. - Evaluate multiple expressions in a new scope.
(do expr1 [expr2…])
Evaluate
expr1
,expr2
, … and return the value of the last expression. - Print documentation in console.
(doc sym)
Print the documentation for
sym
to the console - Evaluate definitions in a new scope and return it.
(export expr1 [expr2…])
Evaluate
expr1
,expr2
, … in a new Scope and return scope. - Export specific symbol definitions as a module/scope.
(export* sym1 [sym2…])
(export*)
Creates a scope containing the symbols
sym1
,sym2
, … and returns it.Copies the containing scope if no symbols are given.
- The boolean constant `false`.
- Declare a function.
(fn (p1 [p2…]) body-expr)
The symbols
p1
,p2
, … will resolve to the arguments passed when the function is invoked. - Make an evaltime const choice.
(if bool then-expr [else-expr])
bool
has to be an evaltime constant. If it is truthy, this expression is equivalent tothen-expr
, otherwise it is equivalent toelse-xpr
if given, or nil otherwise. - Require and define modules.
(import sym1 [sym2…])
Requires modules
sym1
,sym2
, … and define them assym1
,sym2
, … in the current scope. - Require and use modules.
(import* sym1 [sym2…])
Requires modules
sym1
,sym2
, … and merges them into the current scope. - Loop on arbitrary data via recursion.
(loop (k1 v1 [k2 v2…]) body)
Defines a recursive loop function
*recur*
with parametersk1
,k2
, … and function bodybody
, then invokes it immediately with argumentsv1
,v2
, …Inside the
body
,(recur)
is used to recursively restart loop evaluation with a different set of arguments, e.g. to sum the first5
integers:(loop (n 5) (if (= n 0) 0 (+ n (recur (n - 1)))))
- Merge !-streams.
(merge! evt1 evt2 [evt3…])
Merges two or more !-streams of the same type. Whenever any of the input events fires, the output fires the same value.
In case of collisions, the event that comes first in the argument list wins.
- Construct an array.
[a b c…]
(mkarray a b c…)
Produces an array of values.
a
,b
,c
… have to be values of the same type. This is a pure op, so at most one !-stream input is allowed. - Construct an struct.
{key1 val1 [key2 val2…]}
(mkstruct key1 val1 [key2 val2…])
Produces a struct of values.
key1
,key2
, … have to be constant expressions. This is a pure op, so at most one !-stream input is allowed. - Print string values.
(print str)
- Reenter the innermost loop.
(recur nv1 [nv2…])
Reenters the innermost
(loop)
from the top, withk1
bound tonv1
,k2
bound tonv2
…(recur nv1 [nv2…])
is equivalent to(*recur* nv1 [nv2…])
. - Load a module.
(require name)
Load a module and return its scope.
- Switch between multiple inputs.
(switch i v1 v2…)
(switch i arr)
- When fed a num~ or num! stream, reproduces the matching value (indexed starting from 0).
- When fed a bang! trigger, steps forward to the next step on each trigger.
- When fed a bool~ or bool! stream, outputs the first or second value for
true
andfalse
respectively. This version takes at most two values.
When only a single value is provided, it must be an array and is indexed as above.
- Switch between multiple inputs based on normalized i.
(switch-1 i v1 v2…)
(switch i arr)
Like
switch
, but numeric indexes are in the range[0, 1[
. - Trace an expression's values at runtime.
(trace expr)
- Trace an expression's value at evaltime.
(trace= expr)
- The boolean constant `true`.
- Merge scopes into current scope.
(use scope1 [scope2…])
Copy all symbol definitions from
scope1
,scope2
, … to the current scope. All arguments have to be evaltime constant. - Make an evaltime const choice with side effects
(when bool then-exprs…)
bool
has to be an evaltime constant. If it is truthy, this expression is equivalent to(do then-exprs…)
, otherwise it results in nil. - Cast to ~-stream.
(~ event initial)
Casts !-stream to ~-stream by always reproducing the last received value. Since ~-streams cannot be emtpy, specifying an
initial
value is necessary.