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.

dust192B
#_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 /.

dust11B
[- 20 5 3]
Result / 2B
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.

dust21B
[xor true true true]
Result / 4B
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.

dust11B
[< 1 5 10]
Result / 4B
true

The other operators that accept more than two arguments use all of them together. min, max, concat and format have this shape.

Arithmetic

OperatorArgumentsResult
+, *numbers…Fold left. No arguments gives 0 or 1
-, /number, numbers…Fold left. Unary / gives the reciprocal with the input number type
-numberThe negative of the argument
remdividend, divisorThe remainder of the division. The result has the sign of the first argument
%dividend, divisorThe 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.

dust8B
[/ 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.

dust29B
[list [rem -17 5] [% -17 5]]
Result / 6B
[-2 3]

Comparison and equality

OperatorArgumentsResult
<, <=, >, >=number, number, numbers…Exact comparison of integers and floats
=value, value, values…All values equal. [= null null] is true
!=left, rightThe values differ
invalue, listTrue when the value equals (=) an item of the list. [in 2 [list 1 2.0]] is true
notvalueThe opposite true or false value
xorvalue, 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.

dust14B
[xor 0 false]
Result / 4B
true

Three arguments give a range test. < and > keep the value away from both limits. <= and >= accept the value at each limit.

dust13B
[<= 1 10 10]
Result / 4B
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.

dust24B
[and [<= 1 1] [< 1 10]]
Result / 4B
true

Math

OperatorArgumentsResult
abs, incr, decrnumberThe absolute value, one more, or one less
floor, ceil, roundnumberThe number without its fraction
mean, medianlistThe average or the middle value of a list
min, maxnumber, numbers…The smallest or the largest value
clampvalue, low, highA value between a low and a high limit
lerpstart, end, fractionA value between two values
seededRandseed, seeds…The same float from 0 to 1 for the same arguments
powbase, exponentThe first number to the power of the second
sqrtnumberThe square root, a float
expnumbere to the power of the number, a float
log, log2numberThe 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 /.

dust64B
[list [pow 2 10] [pow 2 -1] [sqrt 2] [log2 1024] [log [exp 1]]]
Result / 38B
[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.

dust60B
[list [seededRand ada] [seededRand ada] [seededRand grace]]
Result / 61B
[0.85209372965481489 0.85209372965481489 0.81815489141183417]

Text

OperatorArgumentsResult
concatvalue, values…The arguments as one text
lower, upper, trimtextThe text in one case, or without spaces at its ends
textLengthtextThe number of characters
camel, snake, screamingSnake, kebab, pascaltextThe text in one name style
escapetextThe text with HTML characters replaced
contains, hasPrefixpart, textTrue or false
hasSuffixtext, suffixTrue or false
trimPrefixprefix, textText without that prefix
trimSuffixtext, suffixText without that suffix
indexOf, lastIndexOfneedle, textOne-based character position, or 0
repeatcount, textThe text repeated
split, splitAfterseparator, textThe separator first, then the text
joinseparator, listThe separator first, then the list
replaceold, new, textThe old text, the new text, then the text
substringstart, text or start, size, textThe start, and an optional size. Both accept negative values
formattemplate, 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.

dust38B
[
  format
  '{1:.1f} {0}'
  a
  2.5]
Result / 5B
2.5 a

Collections

OperatorArgumentsResult
length, countlistThe number of items
first, last, rest, reverselistOne part of a list
nthlist, positionThe item at a zero-based position. Out of range is an error
takecount, listThe first items
consitem, listA list with the item at its start
appendfirst-list, second-listThe two lists joined
sumlistThe total of a list of numbers
sort, uniq, flattenlistThe list in order, without repeats, or one level less deep
keys, values, toPairsmapThe parts of a map, in key order
fromPairspairsA map from pairs of name and value
getcollection, key or collection, key, defaultA 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.

dust34B
[sort [list 1 a true null 2.5 2]]
Result / 21B
[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]].

OperatorArgumentsResult
map, filterfunction, listA new list
all, none, any, onefunction, listTrue when that number of items agree
find, findLastfunction, listThe first or last item that agrees, or null
findIndex, findLastIndexfunction, listZero-based position, or -1
groupByfunction, listA map from each calculated key to its items
sortByfunction, list or function, direction, listThe list in the order of a calculated key, with an optional direction
reducefunction, initial, listThe function, the first value, then the list
count, sumfunction, listCounts or adds only the items that the function accepts
dust44B
[all [fn [?value] [> ?value 1]] [list 2 3]]
Result / 4B
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

OperatorArgumentsResult
toIntvalueAn integer from an integer, float, boolean or integer text
toFloatvalueA float from a float, integer or number text
toTextvalueText for any value. Lists and maps give JSON
toBoolvalueA 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.

dust14B
[toInt '4.0']

Error

Runtime_Failure: Cannot change a value of type text into an integer.

Digests

OperatorArgumentsResult
hashvalueThe 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.

dust9B
[hash a]
Result / 74B
{#sha256 ac8d8342bbb2362d13f0a559a3621bb407011368895164b628a54f7fc33fc43c}

Regular expressions

OperatorArgumentsResult
reMatchpattern, textTrue when the pattern matches the text
reFindpattern, textMatched text, or null when no match exists
reReplacepattern, replacement, textThe 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.

dust41B
[reMatch '^catalog-[0-9]+$' catalog-171]
Result / 4B
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.

dust84B
[
  reReplace
  '([0-9]{4})-([0-9]{2})-([0-9]{2})'
  $3/$2/$1
  shipped 2026-09-18]
Result / 18B
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.

dust23B
[reMatch /^ADA$/i ada]
Result / 4B
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).

dust22B
[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!].

dust95B
[list [+] [*] [/ 2] [/ 2.0] [= 3 3 3] [reduce + 0 [list 1 2 3]] [reFind z abc] [reFind ^ abc]]
Result / 26B
[0 1 0 0.5 true 6 null ""]

Run it

build · program evaluate.