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.

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

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

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

dust11 B
[< 1 5 10]
Result / 4 B
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. Integer / truncates toward zero. 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

All arguments must have the same number type. An integer with a float is an error. 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.

dust8 B
[/ 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.

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

Comparison and equality

OperatorArgumentsResult
<, <=, >, >=number, number, numbers…Exact comparison of numbers of one type. An integer with a float is an error
=value, value, values…All values equal. [= null null] is true. [= 1 1.0] is false
!=left, rightThe values differ
invalue, listTrue when the value equals (=) an item of the list. [in 2 [list 1 2.0]] is false
notvalueThe opposite true or false value
xorvalue, values…True when the number of true arguments cannot be divided by 2

Equality compares the type and the value. An integer never equals a float, also inside lists and maps. The float zeros -0.0 and 0.0 are equal, and each keeps its sign. Maps are equal when they have the same keys with equal values, in any order. A missing key is different from a key with the value null. Text compares character codes, without normalization. A function equals only itself: two functions made separately are different, even with the same definition.

JSON Schema validation follows Draft 7's separate decimal number model. It compares the mathematical decimal values in the schema and instance documents: 1 equals 1.0, and 0.1 differs from 0.10000000000000001. Schema integer accepts numbers with no fractional part, including 1.0. Validation preserves the input document and its native numeric types. Host, stored and computed values enter this view through their numeric document representation; validation does not reconstruct an earlier source spelling. Native floats without a fractional part use their exact decimal integer value with .0 when converted to a document. Other native floats use a shortest decimal representation, so native 0.1 enters the schema view as decimal 0.1.

dust30 B
[list [= 1 1.0] [= -0.0 0.0]]
Result / 12 B
[false true]

not and xor use the rule for true and false values: only null and false are false. xor counts the arguments that are true.

dust14 B
[xor 0 false]
Result / 4 B
true

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

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

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

Math

OperatorArgumentsResult
abs, incr, decrnumberThe absolute value, one more, or one less
incrWrap, decrWrapintegerOne more or one less, wrapped in 64 bits
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

min, max and clamp require numbers of one type: all integers or all floats, also inside the single list that min and max accept. Mixed types are an error; convert with toInt or toFloat first. The result is the selected number unchanged, so a whole float stays a float. A tie keeps the first number. clamp requires the low limit not to be greater than the high limit. All operands must be finite, including numbers that are not selected.

dust89 B
[list [max 9007199254740993 9007199254740992] [clamp 1.0 0.0 2.0] [max [toFloat 3] 2.5]]
Result / 26 B
[9007199254740993 1.0 3.0]

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

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

dust60 B
[list [seededRand ada] [seededRand ada] [seededRand grace]]
Result / 61 B
[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.

contains, hasPrefix and hasSuffix give false when an argument is not a text, null included. [hasPrefix a 7] is false. The other text operators fail on a value that is not a text.

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.

dust38 B
[
  format
  '{1:.1f} {0}'
  a
  2.5]
Result / 5 B
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 of one type
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

uniq keeps the first item of each group of equal (=) items.

dust49 B
[uniq [list 2 2.0 [list 2] [list 2.0] -0.0 0.0]]
Result / 22 B
[2 2.0 [2] [2.0] -0.0]

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. Integers and floats sort together by their exact values. An integer comes before a float with the same value.

dust42 B
[sort [list 1 a true null 2.5 2 1.5 1.0]]
Result / 29 B
[null true 1 1.0 1.5 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 text 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
dust44 B
[all [fn [?value] [> ?value 1]] [list 2 3]]
Result / 4 B
true

The groupBy key must be text, because it becomes a map key. Any other key is an error. toText changes a key to text explicitly, so the integer 7 and the text 7 then share one group.

dust70 B
[groupBy [fn [?r] [toText [get ?r code]]] [list {code 7} {code '7'}]]
Result / 25 B
{7 [{code 7} {code '7'}]}

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.

dust14 B
[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, with map keys in order. The float zeros -0.0 and 0.0 give the same digest. The digest of a function comes from its definition and the values that it captures, and Stardust does not call the function. Two functions made separately from the same definition and values have the same digest but are not equal (=). The result is a {#sha256 …} map with hexadecimal digest text.

dust9 B
[hash a]
Result / 74 B
{#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.

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

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

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

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

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

Run it

build · program evaluate.