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.
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 /.
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.
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.
Fold left. Integer / truncates toward zero. 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
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.
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.
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, right
The values differ
in
value, list
True when the value equals (=) an item of the list. [in 2 [list 1 2.0]] is false
not
value
The opposite true or false value
xor
value, 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.
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.
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.
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 /.
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.
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.
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.
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.
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 text 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
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.
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.
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.
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.
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).
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!].