Expression Language Reference¶
Constants¶
Noop¶
Signature: Const
Aliases: _
No operation
Returns true without input validation. Used in place of matchers for uninteresting signals.
Null¶
Signature: Const
Null value
True¶
Signature: Const
Logical true
False¶
Signature: Const
Logical false
Pi¶
Signature: Const
Pi constant
E¶
Signature: Const
Euler's number
Inf¶
Signature: Const
Infinity
Eps¶
Signature: Const
Machine epsilon
NaN¶
Signature: Const
Not a number
Thread¶
Signature: Const
Thread id
Not really a constant, but useful for branching the test input conditions.
Math Functions¶
Sin¶
Signature: Unary
Sinus function
Cos¶
Signature: Unary
Cosinus function
Tan¶
Signature: Unary
Tangens function
Asin¶
Signature: Unary
Arcsin function
Acos¶
Signature: Unary
Arccos function
Atan¶
Signature: Unary
Arctan function
Sinh¶
Signature: Unary
Hyperbolic sin
Cosh¶
Signature: Unary
Hyperbolic cos
Tanh¶
Signature: Unary
Hyperbolic tan
Asinh¶
Signature: Unary
Hyperbolic arcsin
Acosh¶
Signature: Unary
Hyperbolic arccos
Atanh¶
Signature: Unary
Hyperbolic arctan
Exp¶
Signature: Unary
Exponential (e^x)
Erf¶
Signature: Unary
Error function
Erfc¶
Signature: Unary
Error function complement
Gamma¶
Signature: Unary
Gamma function
Abs¶
Signature: Unary
Absolute value
Ceil¶
Signature: Unary
Ceil
Floor¶
Signature: Unary
Floor
Round¶
Signature: Unary
Round to nearest integer
Hint: To round to ndigits precision after the decimal point,
use Mul(ndigits) | Round | Div(ndigits) combo.
Sqrt¶
Signature: Unary
Square root
Sign¶
Signature: Unary
Sign
Arithmetic Operators¶
Neg¶
Signature: Unary
Negate
Examples:
42 | Neg\(\mapsto\)-42
Add¶
Signature: Binary
Addition
Examples:
[2, -1] | Add\(\mapsto\)12 | Add(-1)\(\mapsto\)1
Sub¶
Signature: Binary
Subtraction
Examples:
[2, 1] | Sub\(\mapsto\)-12 | Sub(1)\(\mapsto\)1
Mul¶
Signature: Binary
Multiplication
Examples:
[2, 3] | Mul\(\mapsto\)62 | Mul(3)\(\mapsto\)6
Div¶
Signature: Binary
Division
- \([ ] \mapsto [x, y] \mapsto x / y\)
- \([y] \mapsto [x] \mapsto x / y\)
Examples:
[6, 3] | Div\(\mapsto\)26 | Div(3)\(\mapsto\)2
Pow¶
Signature: Binary
To power
X to power p 1. \([ ] \mapsto [x, p] \mapsto x^p\) 2. \([p] \mapsto [x] \mapsto x^p\)
Examples:
[2, 3] | Pow\(\mapsto\)82 | Pow(3)\(\mapsto\)8
Log¶
Signature: Binary
Logarithm
Logarithm with base b:
- \([ ] \mapsto [x, b] \mapsto log_b(x)\)
- \([b] \mapsto [x] \mapsto log_b(x)\)
Examples:
[8, 2] | Log\(\mapsto\)38 | Log(2)\(\mapsto\)3
Mod¶
Signature: Binary
Modulo
Modulo of x:
- \([ ] \mapsto [x, m] \mapsto x % m\)
- \([m] \mapsto [x] \mapsto x % m\)
Examples:
[7, 4] | Mod\(\mapsto\)37 | Mod(4)\(\mapsto\)3
Quot¶
Signature: Binary
Quotient
Quotient of x:
- \([ ] \mapsto [x, d] \mapsto x // d\)
- \([d] \mapsto [x] \mapsto x // d\)
Examples:
[7, 4] | Quot\(\mapsto\)17 | Quot(4)\(\mapsto\)1
BitNot¶
Signature: Unary
Bitwise not
Examples:
0b1010 | BitNot\(\mapsto\)0b0101
BitAnd¶
Signature: Binary
Bitwise and
Examples:
[0b1010, 0b1100] | BitAnd\(\mapsto\)0b1000
BitOr¶
Signature: Binary
Bitwise or
Examples:
[0b1010, 0b1100] | BitOr\(\mapsto\)0b1110
BitXor¶
Signature: Binary
Bitwise xor
Examples:
[0b1010, 0b1100] | BitXor\(\mapsto\)0b0110
Lshift¶
Signature: Binary
Bitwise left shift
- \([ ] \mapsto [x, s] \mapsto x \texttt{ << } s\)
- \([s] \mapsto [x] \mapsto x \texttt{ << } s\)
Examples:
[0b1010, 2] | Lshift\(\mapsto\)0b101000
Rshift¶
Signature: Binary
Bitwise right shift
- \([ ] ↦ [x, s] ↦ x \texttt{ >> } s\)
- \([s] ↦ [x] ↦ x \texttt{ >> } s\)
Examples:
[0b1010, 2] | Rshift\(\mapsto\)0b0010
Relation Operators¶
Eq¶
Signature: Binary
Is equal
Examples:
[1, 1] | Eq\(\mapsto\)true41 | Eq(42)\(\mapsto\)false
Ne¶
Signature: Binary
Not equal
Examples:
[1, 2] | Ne\(\mapsto\)true42 | Ne(42)\(\mapsto\)false
Lt¶
Signature: Binary
Lesser than
Examples:
[1, 2] | Lt\(\mapsto\)true41 | Lt(42)\(\mapsto\)false
Le¶
Signature: Binary
Lesser or equal
Examples:
[1, 2] | Le\(\mapsto\)true42 | Le(42)\(\mapsto\)true
Gt¶
Signature: Binary
Greater than
Examples:
[2, 1] | Gt\(\mapsto\)true43 | Gt(42)\(\mapsto\)false
Ge¶
Signature: Binary
Greater or equal
Examples:
[2, 1] | Ge\(\mapsto\)true42 | Ge(42)\(\mapsto\)true
Near¶
Signature: Binary
Aliases: Approx
Floating point approximately equal
Based on numpy.isclose:
abs(x - ref) <= (atol + rtol * abs(ref))
Rhs parameters:
ref: reference value rtol: relative tolerance, default = 1e-05 atol: absolute tolerance, default = 1e-08
Rhs dynamic evaluation:
- ref -> [ref, default, default]
- [ref] -> [ref, default, default]
- [ref, rtol] -> [ref, rtol , default]
- [ref, rtol, atol] -> [ref, rtol , atol ]
Examples:
[42, 42] | Approx\(\mapsto\)true42 | Approx(42.0 + 1e-09)\(\mapsto\)true42 | Approx(42.001)\(\mapsto\)false
Relative tolerance 1e-03
* pi | Approx([3.14, 0.001])\(\mapsto\)true
Absolute tolerance 0.01
* pi | Approx([3.14, 0, 0.01])\(\mapsto\)true
Set Operators¶
Union¶
Signature: Binary
Set union
Examples:
[[1, 2], [2, 3]] | Union\(\mapsto\)[1, 2, 3][1, 2] | Union([2, 3])\(\mapsto\)[1, 2, 3]
Intersect¶
Signature: Binary
Set intersection
Examples:
[[1, 2], [2, 3]] | Intersect\(\mapsto\)[2][1, 2] | Intersect([2, 3])\(\mapsto\)[2]
Diff¶
Signature: Binary
Set difference
Examples:
[[1, 2], [2, 3]] | Diff\(\mapsto\)[1][1, 2] | Diff([2, 3])\(\mapsto\)[1]
Set Relation Operators¶
SetEq¶
Signature: Binary
Equal as set
Examples:
[[1, 2], [2, 1]] | SetEq\(\mapsto\)true[1, 2] | SetEq([2, 1])\(\mapsto\)true
Subset¶
Signature: Binary
Is subset
Examples:
[[1, 2], [1, 2, 3]] | Subset\(\mapsto\)true-
[1, 2] | Subset([1, 2, 3])\(\mapsto\)true -
[[1, 2, 3], [2, 3]] | Subset\(\mapsto\)false -
[1, 2, 3] | Subset([2, 3])\(\mapsto\)false -
[[1, 2], []] | Subset\(\mapsto\)true [[], []] | Subset\(\mapsto\)true
Superset¶
Signature: Binary
Is superset
Examples:
[[1, 2, 3], [1, 2]] | Superset\(\mapsto\)true-
[1, 2, 3] | Superset([1, 2])\(\mapsto\)true -
[[2, 3], [1, 2, 3]] | Superset\(\mapsto\)false -
[2, 3] | Superset([1, 2, 3])\(\mapsto\)false -
[[], [1, 2]] | Superset\(\mapsto\)true [[], []] | Superset\(\mapsto\)true
PSubset¶
Signature: Binary
Is proper subset
Examples:
[[1, 2], [1, 2, 3]] | PSubset\(\mapsto\)true-
[1, 2] | PSubset([1, 2, 3])\(\mapsto\)true -
[[1, 2, 3], [2, 3]] | PSubset\(\mapsto\)false -
[1, 2, 3] | PSubset([2, 3])\(\mapsto\)false -
[[1, 2], []] | PSubset\(\mapsto\)true [[], []] | PSubset\(\mapsto\)false
PSuperset¶
Signature: Binary
Is proper superset
Examples:
[[1, 2, 3], [1, 2]] | PSuperset\(\mapsto\)true-
[1, 2, 3] | PSuperset([1, 2])\(\mapsto\)true -
[[2, 3], [1, 2, 3]] | PSuperset\(\mapsto\)false -
[2, 3] | PSuperset([1, 2, 3])\(\mapsto\)false -
[[], [1, 2]] | PSuperset\(\mapsto\)true [[], []] | PSuperset\(\mapsto\)false
In¶
Signature: Binary
Element is in
Examples:
[1, [1, 2]] | In\(\mapsto\)true3 | In([1, 2])\(\mapsto\)false
NotIn¶
Signature: Binary
Element is not in
Examples:
[3, [1, 2]] | NotIn\(\mapsto\)true1 | NotIn([1, 2])\(\mapsto\)false
Ni¶
Signature: Binary
Aliases: Contains
Contains element
Examples:
[[1, 2], 1] | Ni\(\mapsto\)true3 | Ni([1, 2])\(\mapsto\)false
NotNi¶
Signature: Binary
Not contains element
Examples:
[[1, 2], 3] | NotNi\(\mapsto\)true1 | NotNi([1, 2])\(\mapsto\)false
Branching Operators¶
Bool¶
Signature: Unary
Aliases: Truthy
Predicate on boolean transform (aka truthy)
Examples:
42 | Bool\(\mapsto\)true0 | Bool\(\mapsto\)false"false" | Bool\(\mapsto\)true"" | Bool\(\mapsto\)false[1] | Bool\(\mapsto\)true[] | Bool\(\mapsto\)false{} | Bool\(\mapsto\)falsenull | Bool\(\mapsto\)false
Not¶
Signature: Unary
Aliases: Falsy, Nil
Logical complement
Examples:
42 | Nil\(\mapsto\)false0 | Nil\(\mapsto\)true
And¶
Signature: Binary
Logical and
Generic behavior: if first operand is truthy, returns second operand, otherwise first
Examples:
[true, false] | And\(\mapsto\)false[true, true] | And\(\mapsto\)true
Generic behavior:
["foo", [42, 43]] | And\(\mapsto\)[42, 43]-
["" , [42, 43]] | And\(\mapsto\)"" -
13 | And(42)\(\mapsto\)42 [] | And(42)\(\mapsto\)[]
If-Else using composition:
true | And(42) | Or(13)\(\mapsto\)42false | And(42) | Or(13)\(\mapsto\)13
Or¶
Signature: Binary
Logical or
Generic behavior: if first operand is truthy, returns first operand, second otherwise
Examples:
[true, false] | Or\(\mapsto\)true[false, false] | Or\(\mapsto\)false
Generic behavior:
["foo", [42, 43]] | Or\(\mapsto\)"foo"-
["" , [42, 43]] | Or\(\mapsto\)[42, 43] -
13 | Or(42)\(\mapsto\)13 [] | Or(42)\(\mapsto\)42
If-Else using composition:
true | And(42) | Or(13)\(\mapsto\)42false | And(42) | Or(13)\(\mapsto\)13
If¶
Signature: Variadic
Branching operator
Branching operator can be used either in
Lisp-like mode as If(predicate, then_expr, else_expr),
or in pipe mode with Elif or Else operators (see examples).
In pipe mode (without else_expr parameter), the chain will produce
error if the following order is violated or interrupted:
If [ Elif ]* Else
In both modes, then_expr and else_expr are lazy evaluated against
run-time argument (which is also true for Elif and Else), making
it possible to nest if-else expressions.
Examples:
Pipe form:
42 | If(Lt(42), Mul(-1)) | Else(Id)\(\mapsto\)-4267 | If(Lt(42), Mul(-1)) | Else(Id)\(\mapsto\)67
Lisp-like form:
42 | If(Lt(42), Mul(-1), Id)\(\mapsto\)-4267 | If(Lt(42), Mul(-1), Id)\(\mapsto\)67
Nested Lisp-like:
7 | If(42, "42", If(41, "41", Id))\(\mapsto\)742 | If(42, "42", If(41, "41", Id))\(\mapsto\)"41"
Same in pipe form without nesting:
7 | If(42, "42") | Elif(41, "41") | Else(Id)\(\mapsto\)742 | If(42, "42") | Elif(41, "41") | Else(Id)\(\mapsto\)"41"
Elif¶
Signature: Variadic
Else if
Continuation operator in If-Elif-Else pipe. Will fail if not preceded by If. See If.
Else¶
Signature: Binary
Else
Resolving operator in If-Elif-Else pipe. Will fail if not preceded by If or Elif. See If.
Unary Structural transforms¶
Id¶
Signature: Unary
Identity function
Examples:
42 | Id\(\mapsto\)42
Transp¶
Signature: Unary
Transpose multidimensional list, turning rows into columns
May be used to zip sequences of equal length.
Examples:
[[1, 2, 3], [4, 5, 6]] | Transp\(\mapsto\)[[1, 4], [2, 5], [3, 6]]
Cartesian¶
Signature: Unary
Cartesian product
Examples:
[[1, 2], [3, 4]] | Cartesian\(\mapsto\)[[1, 3], [1, 4], [2, 3], [2, 4]]
Reverse¶
Signature: Unary
Reverse sequence
Examples:
[1, 2, 3] | Reverse\(\mapsto\)[3, 2, 1]
Uniques¶
Signature: Unary
Filter unique elements
Examples:
[1, 2, 1, 3, 2] | Uniques\(\mapsto\)[1, 2, 3]
Items¶
Signature: Unary
Extract key-value pairs from object
Examples:
{"a": 1, "b": 2} | Items\(\mapsto\)[["a", 1], ["b", 2]]
Keys¶
Signature: Unary
Extract keys from object
Examples:
{"a": 1, "b": 2} | Keys\(\mapsto\)["a", "b"]
Values¶
Signature: Unary
Extract values from object
Examples:
{"a": 1, "b": 2} | Values\(\mapsto\)[1, 2]
Enumerate¶
Signature: Unary
Enumerate sequence
Enumerate sequence with index.
Examples:
[1, 2, 3] | Enumerate\(\mapsto\)[[0, 1], [1, 2], [2, 3]]
Flatten¶
Signature: Unary
Flatten nested list
Examples:
[[1, 2], [3, 4]] | Flatten\(\mapsto\)[1, 2, 3, 4]
ToList¶
Signature: Unary
Put argument into a list
Equivalent to At([""])
Examples:
42 | List\(\mapsto\)[42]
First¶
Signature: Unary
First item of sequence
Equivalent to At(0)
Examples:
[1,2,3] | First\(\mapsto\)1[] | First\(\mapsto\)null
Last¶
Signature: Unary
Last item of sequence
Equivalent to At(-1)
Examples:
[1,2,3] | Last\(\mapsto\)3[] | Last\(\mapsto\)null
Random number generators¶
Rand¶
Signature: Unary
Uniformly distributed random number in the half-open interval [0.0, 1.0)
RandInt¶
Signature: Variadic
Uniformly distributed random integer in the given range
RandInt(x, y) : range is [x, y] RandInt(x) : range is [0, x] for positive x and [x, 0] for negative RandInt() : range is [0, RAND_MAX]
Sequence Generators¶
Sequence¶
Signature: Binary
Aliases: Seq
Produce sequence from parameter using arg as size
Behavior of n | Sequence(F)is similar to n | Flip(Repeat(F)),
with the main difference that the parameter is reevaluated for each step,
making it possible to utilize side-effects, s.a. with Rand.
Examples:
3 | Sequence(42)\(\mapsto\)[42, 42, 42]3 | Sequence(Rand)\(\mapsto\)[..., ..., ...]
Arange¶
Signature: Unary
Generate range of numbers
Return evenly spaced values within a given interval.
Parameters:
- start: start value
- stop: stop value
- step: step value
Parameters dynamic evaluation:
- stop: int -> [0, stop, 1]
- [start, stop] -> [start, stop, 1]
- [start, stop, step] -> [start, stop, step]
Examples:
6 | Arange\(\mapsto\)[0,1,2,3,4,5][2,6] | Arange\(\mapsto\)[2,3,4,5][1,9,2] | Arange\(\mapsto\)[1,3,5,7]-
[5,1,-1] | Arange\(\mapsto\)[5,4,3,2] -
"2:6" | Arange\(\mapsto\)[2,3,4,5] "1:9:2" | Arange\(\mapsto\)[1,3,5,7]"5:1:-1" | Arange\(\mapsto\)[5,4,3,2]
String Transforms¶
Parse¶
Signature: Unary
Parse string as json
Examples:
'{"a": 42}' | Parse\(\mapsto\){"a": 42}
Str¶
Signature: Unary
Aliases: Serialize
Serialize json as string
Examples:
{"a": 42} | Serialize\(\mapsto\)'{"a":42}'
Re¶
Signature: Binary
Aliases: Regex
Regular expression match
If input is not a string, match it's serialized form.
Examples:
["[0-9]+", "42"] | Re\(\mapsto\)true"42" | Re("[0-9]+")\(\mapsto\)true
Fmt¶
Signature: Variadic
Aliases: Format
Format string with the given parameter list.
Constant expressions are supported for the token list,
s.t. "%s" | Fmt(Pi) produces "3.141592653589793E0"
Examples:
["Hello, %s!", ["world"]] | Format\(\mapsto\)"Hello, world!""%d + %d = %d" | Format(2,2,4)\(\mapsto\)"2 + 2 = 4"
Capitalize¶
Signature: Unary
Capitalize string
Examples:
"foo" | Capitalize\(\mapsto\)"Foo"
LowerCase¶
Signature: Unary
Lower case string
Examples:
"Foo" | LowerCase\(\mapsto\)"foo"
UpperCase¶
Signature: Unary
Upper case string
Examples:
"foo" | UpperCase\(\mapsto\)"FOO"
Structural properties¶
Card¶
Signature: Unary
Set cardinality (uniques count)
Examples:
[1, 2, 1, 3, 2] | Card\(\mapsto\)3{"a": 1, "b": 2} | Card\(\mapsto\)2
Size¶
Signature: Unary
Sequence size
Examples:
[1, 1, 1] | Size\(\mapsto\)3{"a": 1, "b": 2} | Size\(\mapsto\)2
Sum¶
Signature: Unary
Summation reduction
Equivalent to Reduce(Add)
Examples:
[1, 2, 3] | Sum\(\mapsto\)6
Prod¶
Signature: Unary
Multiplication reduction
Equivalent to Reduce(Mul)
Examples:
[1, 2, 3] | Prod\(\mapsto\)6
Avg¶
Signature: Unary
Arythmetic average
Examples:
[1, 2, 3] | Avg\(\mapsto\)2
Binary Structural transforms¶
Slide¶
Signature: Binary
Sliding-window iteration
Sliding window iteration by specified window width.
Examples:
[1,2,3,4,5] | Slide(3)\(\mapsto\)[[1,2,3],[2,3,4],[3,4,5]][1,2,3,4,5] | Slide(42)\(\mapsto\)[]
Stride¶
Signature: Binary
Striding iteration
Striding iteration by specified step width. Reminder subsequence smaller then step width is discarded.
Examples:
[1,2,3,4,5,6] | Stride(2)\(\mapsto\)[[1,2],[3,4],[5,6]][1,2,3,4,5] | Stride(3)\(\mapsto\)[[1,2,3]]
Chunks¶
Signature: Binary
Split into chunks of specified max width
Similar to Stride, but includes the last subsequence smaller then step width.
Examples:
[1,2,3,4,5,6] | Chunks(2)\(\mapsto\)[[1,2],[3,4],[5,6]][1,2,3,4,5] | Chunks(3)\(\mapsto\)[[1,2,3],[4,5]]
Repeat¶
Signature: Binary
Repeat value in list
Examples:
42 | Repeat(3)\(\mapsto\)[42, 42, 42]1 | Repeat(3) | Repeat(2)\(\mapsto\)[[1,1,1],[1,1,1]]
Cat¶
Signature: Binary
Aliases: Concat
Concatenate sequences
Examples:
[[1, 2], [3, 4]] | Concat\(\mapsto\)[1, 2, 3, 4]"Hello, " | Concat("World!")\(\mapsto\)"Hello, World!"
Push¶
Signature: Binary
Push element into a front of sequence
Examples:
[[1, 2], 3] | Push\(\mapsto\)[3, 1, 2][1, 2] | Push(3)\(\mapsto\)[3, 1, 2]
At¶
Signature: Binary
Transform json value with given query
Query evaluation rules:
- Structure index (negative resolves as reverse): \(q: int \mapsto x: list \mapsto x_q\)
- Array slice: \(q: slice \mapsto x: list \mapsto x[start:stop:step]\)
- JSON Pointer: \(q: str \mapsto x: any \mapsto x_q\)
- Array pack: \(q: list \mapsto x: any \mapsto [x_{q_1}, x_{q_2}, ...]\)
- Object pack: \(\{key: q_1, \$q_2: q_3, ...\} \mapsto x: any \mapsto \{ key: x_{q_1}, q_2: x_{q_3}, ...\}\)
Structure index is evaluated as array index or as key-value pair index for objects on order-preserving backends.
Result is null if requested element not found.
Examples:
Array index:
[1, 2, 3] | At(2)\(\mapsto\)3[1, 2, 3] | At(3)\(\mapsto\)nullptr42 | At(0)\(\mapsto\)nullptr
Array slice:
[1,2,3,4,5,6,7,8] | At("::2")\(\mapsto\)[1,3,5,7][1,2,3,4,5,6,7,8] | At("4:")\(\mapsto\)[5,6,7,8][1,2,3,4,5,6,7,8] | At("-1:0:-1")\(\mapsto\)[8,7,6,5,4,3,2,1]
JSON Pointer:
"foo" | At("")\(\mapsto\)"foo"{"a": 42, "b": 13} | At("/a")\(\mapsto\)42
Array pack:
{"a": 42, "b": 13} | At(["/a", "/b"])\(\mapsto\)[42, 13]42 | At([""])\(\mapsto\)[42]
Object pack:
{"a": 42, "b": 13} | At({"f": "/a", "g": "/b"})\(\mapsto\){"f": 42, "g": 13}{"a": 42, "b": 13} | At({"$/b": "/a"})\(\mapsto\){"13": 42}
Del¶
Signature: Binary
Aliases: Delete
Delete elements from structure by given query
Possible queries: 1. Structure index (negative resolves as reverse) 2. JSON Pointer 3. List of queries
Structure index is evaluated as array index or as key-value pair index for objects on order-preserving backends. When deleting an object element, resulting items order may change.
Examples:
[1,2,3,4,5] | Del(2)\(\mapsto\)[1,2,4,5][[1, 2], 3] | Del("/0/1")\(\mapsto\)[[1], 3]{"a": {"b": [1,2,3]}} | Del({"/a/b/0", "/a/b/1"})\(\mapsto\){"a": {"b": [3]}}
Lookup¶
Signature: Binary
Lookup table function
Parametrized at design time with fixed array or object, produces the value at corresponding At query given as eval-time argument. Equivalent to ~At(...)
Examples:
0 | Lookup([1,2,3])\(\mapsto\)1"/foo" | Lookup([1,2,3])\(\mapsto\)null
Cast¶
Signature: Special
Aliases: Decorate
Reserialize decorated type as decorator
Uncast¶
Signature: Special
Aliases: Undecorate
Reserialize decorator as decorated type
High-Order¶
Fold¶
Signature: Binary
Aliases: Reduce
Reduce sequence with binary operator
To set a specific initial value, use composition with Push, e.g.
Push(0) | Fold(Add)
For reverse operation, see Unfold
Examples:
[-1, 2, 3] | Fold(Add)\(\mapsto\)4[-1, 2, 3] | Fold(Mul)\(\mapsto\)-6
Map¶
Signature: Binary
Apply param expr to every element of sequence
Examples:
[1, 2, 3] | Map(Add(1))\(\mapsto\)[2, 3, 4]
Filter¶
Signature: Binary
Filter sequence by predicate param
Examples:
[1, 2, 3, 4] | Filter(Gt(2))\(\mapsto\)[3, 4]
Count¶
Signature: Binary
Count matches by predicate param
Examples:
[1, 2, 3, 4] | Count(Gt(2))\(\mapsto\)2
Each¶
Signature: Binary
Test predicate for each item in a sequence
Equivalent to Count(p | Not) | Eq(0)
Examples:
[1, 2, 3, 4] | Each(Gt(2))\(\mapsto\)false[1, 2, 3, 4] | Slide(2) | Each(Lt)\(\mapsto\)true
Sort¶
Signature: Binary
Sort list by key function
Examples:
[3, 1, 2] | Sort\(\mapsto\)[1, 2, 3][3, 1, 2] | Sort(Id)\(\mapsto\)[1, 2, 3][-3, 1, -2] | Sort(Abs)\(\mapsto\)[1, -2, -3][3, 1, 2] | Sort | Reverse\(\mapsto\)[3, 2, 1]
Find¶
Signature: Binary
Find the first element that satisfies given predicate
Examples:
[-3, 1, -2] | Find(Ge(2))\(\mapsto\)nullptr[-3, 1, 4] | Find(Ge(2))\(\mapsto\)4
FindPtr¶
Signature: Binary
Find json pointer of the first element that satisfies given predicate
Examples:
[-3, 1, -2] | FindPtr(Ge(2))\(\mapsto\)nullptr[-3, 1, 4] | FindPtr(Ge(2))\(\mapsto\)"/2"
FindIdx¶
Signature: Binary
Find index of the first element that satisfies given predicate
Similar to FindPtr, but will integer index or nullptr for non-indexable input. Objects are processed as list of key-value pairs.
Examples:
[-3, 1, -2] | FindIdx(Ge(2))\(\mapsto\)nullptr[-3, 1, 4] | FindIdx(Ge(2))\(\mapsto\)2
Min¶
Signature: Binary
Min value by key function
Examples:
[-3, 1, -2] | Min\(\mapsto\)1[-3, 1, -2] | Min(Abs)\(\mapsto\)-3
Max¶
Signature: Binary
Max value by key function
Examples:
[-3, 1, -2] | Max\(\mapsto\)1[-3, 1, -2] | Max(Abs)\(\mapsto\)-3
Argmin¶
Signature: Binary
Min value index by key function
Examples:
[-3, 1, -2] | Argmin\(\mapsto\)0[-3, 1, -2] | Argmin(Abs)\(\mapsto\)1
Argmax¶
Signature: Binary
Max value index by key function
Examples:
[-3, 1, -2] | Argmax\(\mapsto\)1[-3, 1, -2] | Argmax(Abs)\(\mapsto\)0
Recur¶
Signature: Variadic
Apply recursion to parameter expr and initial value
Inference rules:
n | Recur(x, f)\(\mapsto ◯ⁿ f(x)\), or-
Q(p) | Recur(x₀, f)\(\mapsto x_k\), where- \(x_{i+1} = f(x_i)\)
- \(p(x_{i}) = \top \quad \forall i \le k\)
- \(p(x_{i+1}) = \bot\) (exit condition)
Examples:
0 | Recur(0, Add(1))\(\mapsto\)33 | Recur(1, Mul(-1))\(\mapsto\)-1
Unfold¶
Signature: Variadic
Put results of recursive fn call on initial value into an array
Inference rules:
n | Unfold(x, f)\(\mapsto [x_0, x_1, ..., x_n]\), or-
Q(p) | Unfold(x₀, f)\(\mapsto [x_0, x_1, ..., x_k]\), where- \(x_{i+1} = f(x_i)\)
- \(p(x_{i}) = \top \quad \forall i \le k\)
- \(p(x_{i+1}) = \bot\) (exit condition)
Examples:
3 | Unfold(0, Add(1))\(\mapsto\)[0, 1, 2, 3]3 | Unfold(1, Mul(-1))\(\mapsto\)[1,-1, 1,-1]
Op¶
Signature: Special
Aliases: Overload
Bind type-specific operator handler to function
Expression Op(op, f) instructs f to use op operator on invocation instead of the default generic.
Operator parameter singleton can be referenced with a
string key or constructed in place using type
This operator handler is propagated downstream to all terminal
subexpression in f.
The result of f(x) is not decorated as type
Examples:
[0.5, 2] | Op("complex", Add(1))\(\mapsto\)[1.5, 2]
Bind¶
Signature: Binary
Bind design-time parameters to function.
Examples:
42 & Q(Add) | Bind\(\mapsto\)Add(42)42 | Bind(F) | Bind(G) | Bind(H)\(\mapsto\)H(G(F(42)))
Fn¶
Signature: Variadic
Symbolic binding of the inline function
Expression Fn(reference, expr) creates a symbolic binding between the given
reference and an expression, making the expression callable by name within
the evaluation context.
The referenced expression is inlined at the call site and evaluated with the current input. The reference is available to the bound expression itself and to all its subexpressions, enabling arbitrary recursion.
Each invocation of a function bound with Fn establishes a local scope for
argument bindings created via Link, forming a lexical closure over the
surrounding bindings. Argument links from outer scopes are captured by the
function and remain accessible unless shadowed by a local binding.
Such captured values can be explicitly read using the Get expression
Function bindings are shared across the whole expression and are immutable:
once a reference is bound with Fn, it cannot be redefined or reset.
Infix operator form (left shift):
"$f" << E ≡ Fn("$f", E)
Examples:
Recursive factorial:
auto const factorial = "$f" << ("$x"
| Assert(Ge(0))
| Lt(2)
| And(1)
| Or("$x" | Sub(1) | "$f" | Mul("$x"))
);
Link¶
Signature: Binary
Symbolic binding of the input value
Capture the current input value and associate it with a symbolic
reference represented by a dollar-prefixed string, e.g. "$x".
On its first evaluation, the reference stores the input value (similar to variable initialization) and passes the value further through the pipeline. On subsequent evaluations within the same scope, the stored value is returned, acting as an immutable constant.
A Link instance cannot be reset after its first access. However, it may be
shadowed by another binding with the same reference name in a nested scope,
such as a recursive call created with Fn.
The reference name following the $ sign must not be enclosed in [], {},
or (), as those formats are reserved for internal use.
Examples:
42 | "$x" | Ge(0) | And("$x") | Or("$x" | Mul(-1))\(\mapsto\)42-7 | "$x" | Ge(0) | And("$x") | Or("$x" | Mul(-1))\(\mapsto\)7
Get¶
Signature: Binary
Load linked value (maybe a closure) or return null
Explicitly load the value bound to a symbolic reference without triggering capture semantics.
In contexts where a $-prefixed reference would otherwise attempt to
initialize a new binding, Get forces a read of an existing binding from
the nearest enclosing scope. If no such binding exists, null is returned.
This is particularly useful when working with immutable closures and recursive expressions, where it is necessary to distinguish between reading an upvalue and introducing a new local binding.
Examples:
"$x" | Add(1) // captures input into \(x on first encounter Get("\)x") | Add(1) // reads existing binding without capturing
EnvLoad¶
Signature: Binary
Load value from the test environment using json pointer
Load the the value from a global environment table with a given JSON Pointer.
EnvStore¶
Signature: Binary
Store value in the test environment using json pointer
Capture the argument value and store it in a global environment table with a given JSON Pointer, passing the value further similarly to Link.
Any¶
Signature: Variadic
Match any predicate
Examples:
3 | Any(Gt(2), Lt(0))\(\mapsto\)true0 | Any(Gt(2), Lt(0))\(\mapsto\)false
All¶
Signature: Variadic
Match all predicates
Examples:
3 | All(Gt(2), Lt(0))\(\mapsto\)false2.5 | All(Gt(2), Lt(3))\(\mapsto\)true
Saturate¶
Signature: Variadic
Saturate matches in order
Examples:
3 | Saturate(Gt(2), Lt(0))\(\mapsto\)true-
0 | Saturate(Gt(2), Lt(0))\(\mapsto\)false -
[2,4,8,42,1,2] | Saturate(42, Mod(2)|0)\(\mapsto\)true [2,4,8,41,2] | Saturate(42, Mod(2)|0)\(\mapsto\)false[2,4,8,42] | Saturate(42, Mod(2)|0)\(\mapsto\)false
Pipe¶
Signature: Variadic
Pipe functions in left-to-right composition
Examples:
3 | Pipe(Mul(2), Add(1))\(\mapsto\)74 | Pipe(Mul(2), Add(1))\(\mapsto\)9
Infix operator form (pipe):
Add(1) | Mul(2)\(\equiv\)Pipe(Add(1), Mul(2))3 | Add(1) | Mul(2)\(\mapsto\)8
Tuple¶
Signature: Variadic
Pack expressions into an tuple without evaluation
Examples:
null | Tuple(Reduce(Add), Size)\(\mapsto\)[Reduce(Add), Size]
Infix operator form (comma):
(Add(1), Mul(2))\(\equiv\)Tuple(Add(1), Mul(2))
Fork¶
Signature: Variadic
Pack results from enveloped functions into an array
Parallel composition operator:
Examples:
[1,2,3] | Fork(Reduce(Add), Size)\(\mapsto\)[6,3][1,2,3] | Fork(42, Card, Id)\(\mapsto\)[42, 3, [1,2,3]]
Infix operator form (ampersand):
Add(1) & Mul(2)\(\equiv\)Fork(Add(1), Mul(2))[1,2,3] | Reduce(Add) & Size\(\mapsto\)[6,3][1,2,3] | Reduce(Add) & Size | Div\(\mapsto\)2
Note that the Fork is not associative,
therefore an infix operator chain is not unfolded
as it is done for variadic Pipe or Tuple:
* a & b & c\(\equiv\)(a & b) & c\(\equiv\)Fork(Fork(a, b), c)
Flip¶
Signature: Binary
Flip design-time and eval-time parameters.
Useful for binding lhs operands to non-commutative operators. Unlike Haskell's flip, won't change the order or eval-time parameters - for that case use the Reverse keyword instead.
Prefix operator form (tilde):
Flip(Div(1)) ≡ ~Div(1)
Examples:
2 | Div(1)\(\mapsto\)2/12 | ~Div(1)\(\mapsto\)1/2
Dbg¶
Signature: Binary
Aliases: Debug
Evaluate function and print evaluation log to stderr
Examples:
42 | Dbg(Trace(ZMBT_CUR_LOC) | Add(2))
Eval¶
Signature: Binary
Flip designtime and run-time parameters, evaluating input as expression
Try¶
Signature: Binary
Evaluate function and return result or null if it returns error
Examples:
42 | Try(Add(1))\(\mapsto\)43"foo" | Try(Add(1))\(\mapsto\)null
Kwrd¶
Signature: Unary
Introspect expression keyword.
Examples:
Q(Fold(Add)) | Kwrd\(\mapsto\)"Fold"[1, 1, 1] | Kwrd\(\mapsto\)"Literal"
Prms¶
Signature: Unary
Aliases: Parameters
Introspect expression parameters.
Examples:
Q(Fold(Add)) | Prms\(\mapsto\)Add[1, 1, 1] | Prms\(\mapsto\)[1, 1, 1]
Evaluation handlers¶
Q¶
Signature: Binary
Aliases: C, Const
Quote parameter, similar to lisp quotation.
Quotation lifts any parameter to constant, s.t. produced expression will return the design-time parameter on evaluation, ignoring input. If evaluable expression is passed, it is returned unevaluated. Unlike plain literals which can be treated as predicate matchers in certain context, Q(x) is always a constant expression discarding input. ~Q (Flip(Q)) is equivalent to Id.
Examples:
null | C(42)\(\mapsto\)42
D¶
Signature: Binary
Aliases: Default
Return x if not null, else return default value
Examples:
null | Default(42)\(\mapsto\)4213 | Default(42)\(\mapsto\)13
Err¶
Signature: Special
Aliases: Error
Error object
Error object handling the message and context info
IsErr¶
Signature: Unary
Aliases: IsError
Test the argument is err expression
Assert¶
Signature: Binary
Return argument if it holds assertion or error otherwise.
Examples:
42 | Assert(Ge(0))\(\mapsto\)42-7 | Assert(Ge(0))\(\mapsto\)Err("assertion failed", "-7 | Ge(0)")
Trace¶
Signature: Binary
Same as id, but also prints identifier parameter to debug log.
PreProc¶
Signature: Binary
Preprocessing token
String token that can be substituted with arbitrary expression on expression preprocessing.
Examples:
null | C(42)\(\mapsto\)42