Operators
An expression combines operators to calculate its result. Each operator defines its accepted arguments and result. The Arguments column gives argument names in their accepted order. Stardust rejects the wrong number of arguments. It also rejects an argument of the wrong type.
#_ada {name Ada
role engineer
age 36}
#_bob {name Bob
role engineer
age 41
mentor {#link #_ada}}
#_cy {name Cy
role designer
age 29}
More than two arguments
Operators that accept more than two arguments use a fold, a chain, or all arguments together.
A fold applies the operator again to its own result. +, -, * and / have
this shape, and [+ 1 2 3] is [+ [+ 1 2] 3]. A fold goes from left to right,
which changes the result of - and /.
[- 20 5 3]
12
xor has this shape. [xor a b c] is [xor [xor a b] c], and xor is
therefore true when the number of true arguments cannot be divided by 2. Three
true arguments give true.
[xor true true true]
true
A chain applies the operator to each pair of adjacent arguments. <, <=, >
>= and = have this shape. [< 1 5 10] requires 1 to be less than 5 and 5 to be less than 10.
It does not compare a true or false value against 10.
[< 1 5 10]
true
The other operators that accept more than two arguments use all of them
together. min, max, concat and format have this shape.
Arithmetic
| Operator | Arguments | Result |
|---|---|---|
+, * | numbers… | Fold left. No arguments gives 0 or 1 |
-, / | number, numbers… | Fold left. Unary / gives the reciprocal with the input number type |
- | number | The negative of the argument |
rem | dividend, divisor | The remainder of the division. The result has the sign of the first argument |
% | dividend, divisor | The modulus of the division. The result has the sign of the second argument |
An integer result of more than 64 bits is an error. Division by zero is also an
error. rem and % reject a divisor of zero in the same way.
[/ 1 0]
Error
Runtime_Failure: The divisor must not be zero.
rem and % give the same result when both arguments are more than zero. The
results are different when one argument is less than zero. rem keeps the sign
of the first argument, and % keeps the sign of the second argument.
[list [rem -17 5] [% -17 5]]
[-2 3]
Comparison and equality
| Operator | Arguments | Result |
|---|---|---|
<, <=, >, >= | number, number, numbers… | Exact comparison of integers and floats |
= | value, value, values… | All values equal. [= null null] is true |
!= | left, right | The values differ |
in | value, list | True when the value equals (=) an item of the list. [in 2 [list 1 2.0]] is true |
not | value | The opposite true or false value |
xor | value, values… | True when the number of true arguments cannot be divided by 2 |
not and xor use the rule for true and false values: only null and false
are false. xor counts the arguments that are true.
[xor 0 false]
true
Three arguments give a range test. < and > keep the value away from both
limits. <= and >= accept the value at each limit.
[<= 1 10 10]
true
One operator gives the same type of limit on each side. If the two limits are
not the same type, use and with two comparisons. This example accepts a value
at the low limit but not at the high limit.
[and [<= 1 1] [< 1 10]]
true
Math
| Operator | Arguments | Result |
|---|---|---|
abs, incr, decr | number | The absolute value, one more, or one less |
floor, ceil, round | number | The number without its fraction |
mean, median | list | The average or the middle value of a list |
min, max | number, numbers… | The smallest or the largest value |
clamp | value, low, high | A value between a low and a high limit |
lerp | start, end, fraction | A value between two values |
seededRand | seed, seeds… | The same float from 0 to 1 for the same arguments |
pow | base, exponent | The first number to the power of the second |
sqrt | number | The square root, a float |
exp | number | e to the power of the number, a float |
log, log2 | number | The natural or the base-2 logarithm, a float |
pow gives an integer when both numbers are integers and the power is zero or
more. Such a result must fit in 64 bits, as for *. Other powers give a float.
sqrt requires a number that is not negative, and log and log2 require a
number greater than zero. A result that is not finite is an error, as for /.
[list [pow 2 10] [pow 2 -1] [sqrt 2] [log2 1024] [log [exp 1]]]
[1024 0.5 1.4142135623730951 10.0 1.0]
seededRand gives the same number for the same arguments on every machine and
every run. A value that must be irregular but must not change between runs
therefore needs no stored database field.
[list [seededRand ada] [seededRand ada] [seededRand grace]]
[0.85209372965481489 0.85209372965481489 0.81815489141183417]
Text
| Operator | Arguments | Result |
|---|---|---|
concat | value, values… | The arguments as one text |
lower, upper, trim | text | The text in one case, or without spaces at its ends |
textLength | text | The number of characters |
camel, snake, screamingSnake, kebab, pascal | text | The text in one name style |
escape | text | The text with HTML characters replaced |
contains, hasPrefix | part, text | True or false |
hasSuffix | text, suffix | True or false |
trimPrefix | prefix, text | Text without that prefix |
trimSuffix | text, suffix | Text without that suffix |
indexOf, lastIndexOf | needle, text | One-based character position, or 0 |
repeat | count, text | The text repeated |
split, splitAfter | separator, text | The separator first, then the text |
join | separator, list | The separator first, then the list |
replace | old, new, text | The old text, the new text, then the text |
substring | start, text or start, size, text | The start, and an optional size. Both accept negative values |
format | template, value, values… | The template first, then its arguments |
Stardust counts and cuts text in characters. [textLength héllo] gives 5.
format uses {} in sequence and {0} by position. {{}} gives one brace.
A specification after : must suit the type of its value. An integer accepts
b, c, d, o, x, X and U. A float accepts e, E, f, F, g
and G, and a text accepts s. A float specification over an integer is an
error, as [format '{:.2f}' 42] is.
[
format
'{1:.1f} {0}'
a
2.5]
2.5 a
Collections
| Operator | Arguments | Result |
|---|---|---|
length, count | list | The number of items |
first, last, rest, reverse | list | One part of a list |
nth | list, position | The item at a zero-based position. Out of range is an error |
take | count, list | The first items |
cons | item, list | A list with the item at its start |
append | first-list, second-list | The two lists joined |
sum | list | The total of a list of numbers |
sort, uniq, flatten | list | The list in order, without repeats, or one level less deep |
keys, values, toPairs | map | The parts of a map, in key order |
fromPairs | pairs | A map from pairs of name and value |
get | collection, key or collection, key, default | A map key or a list position, with an optional default |
get gives null for a missing key or position. Its third argument sets a
different default. nth rejects a position outside the list.
Stardust sorts values of different types in this sequence: null, booleans,
numbers, text, then collections.
[sort [list 1 a true null 2.5 2]]
[null true 1 2 2.5 a]
Operators that use a function
Each operator in this group has a function first. The input
list is last, including forms with an initial value or direction. A built-in
operator can be a function, as in [reduce + 0 [list 1 2 3]].
| Operator | Arguments | Result |
|---|---|---|
map, filter | function, list | A new list |
all, none, any, one | function, list | True when that number of items agree |
find, findLast | function, list | The first or last item that agrees, or null |
findIndex, findLastIndex | function, list | Zero-based position, or -1 |
groupBy | function, list | A map from each calculated key to its items |
sortBy | function, list or function, direction, list | The list in the order of a calculated key, with an optional direction |
reduce | function, initial, list | The function, the first value, then the list |
count, sum | function, list | Counts or adds only the items that the function accepts |
[all [fn [?value] [> ?value 1]] [list 2 3]]
true
Type tests
isNull, isBool, isText, isInt, isFloat, isNumber, isEntity,
isTagged, isList and isMap each have one argument. Each one gives true
or false. isInt and isFloat separate the two kinds of number. isNumber
accepts both kinds.
Type changes
| Operator | Arguments | Result |
|---|---|---|
toInt | value | An integer from an integer, float, boolean or integer text |
toFloat | value | A float from a float, integer or number text |
toText | value | Text for any value. Lists and maps give JSON |
toBool | value | A boolean from a boolean, 'true', 'false', 1 or 0 |
A value that an operator cannot change gives an error. There is no fallback value. Expressions gives the full rules.
[toInt '4.0']
Error
Runtime_Failure: Cannot change a value of type text into an integer.
Digests
| Operator | Arguments | Result |
|---|---|---|
hash | value | The SHA-256 digest of the value, as a digest map |
Stardust calculates the digest from the JSON form of the value. The result
is a {#sha256 …} map with hexadecimal digest text.
[hash a]
{#sha256 ac8d8342bbb2362d13f0a559a3621bb407011368895164b628a54f7fc33fc43c}Regular expressions
| Operator | Arguments | Result |
|---|---|---|
reMatch | pattern, text | True when the pattern matches the text |
reFind | pattern, text | Matched text, or null when no match exists |
reReplace | pattern, replacement, text | The text with each match replaced |
The pattern is first. reReplace has the replacement second and input text
last. An empty match gives empty text. An absent match gives null.
[reMatch '^catalog-[0-9]+$' catalog-171]
true
reReplace changes every match. In the replacement, $1 to $9 are the groups
that the pattern captured. $0 is the whole match. $ is one dollar sign.
[
reReplace
'([0-9]{4})-([0-9]{2})-([0-9]{2})'
$3/$2/$1
shipped 2026-09-18]
shipped 18/09/2026
A pattern can start and end with / to add flags. The i flag ignores case.
The m flag lets ^ and $ match at each line. The x flag ignores spaces
in the pattern. The u flag reads the text as Unicode.
[reMatch /^ADA$/i ada]
true
The pattern language
A pattern accepts alternation a|b and classes [0-9] and [^0-9]. It also
accepts the ASCII shorthands \d \s \w and their negations. The wildcard
is .. Repeats use *, +, ?, or {1,2}, with ? for non-greedy
matching. Groups use (a) or (?:a). Anchors are ^ and $, and word
boundaries are \b and \B.
A pattern can have 9 groups. Stardust rejects a pattern with more groups.
It also rejects group references such as \1, look-ahead (?=a),
look-behind (?<=a), and group names such as (?<year>a).
[reMatch (?=foo) foo]
Error
Runtime_Failure: The regular expression is not valid.
Matching examines each text position one time. It does not try each choice
again, so the following expression gives false immediately:
[reMatch (a+)+$ aaaaaaaaaaaaaaaaaaaaaaaa!].
[list [+] [*] [/ 2] [/ 2.0] [= 3 3 3] [reduce + 0 [list 1 2 3]] [reFind z abc] [reFind ^ abc]]
[0 1 0 0.5 true 6 null ""]