Expressions
The syntax gives names for branches and local variables.
An expression combines those forms into a program written as data.
The first item in a list is
the operator. The other items are its arguments. You write 2 + 3 * 4 in this
form:
[+ 2 [* 3 4]]
14
An expression is an ordinary document. Stardust keeps it, examines it, and records each change to it. A native document keeps the expression without a text conversion. DUST gives a readable form of that document.
#_ada {name Ada
role engineer
age 36}
#_bob {name Bob
role engineer
age 41
mentor {#link #_ada}}
#_cy {name Cy
role designer
age 29}
Variables
Every variable binding and reference uses ?name, including let names and
fn parameters. A reference uses the inner declaration first. A reference
without a declaration reads caller input. A plain word in value position is
always text.
[+ ?x 1]
- x
- 41
42
With the caller variable x set to 41, this expression gives 42. An
expression contains no inputs and no results. Each evaluation gives one value
and the cost of the calculation.
An expression calculates its result from its variables. A standalone expression needs no database or external service.
True and false values
Only null and false are false. All other values are true. The number 0,
the empty text, and the empty list are also true. The branch
operators use this rule.
[if 0 zero-is-true never]
zero-is-true
Exact numbers
An integer has 64 bits and keeps its exact value. A float has 64 bits in binary form. Stardust does not change the type of a value automatically. Each operator sets the type of its arguments. One argument with a known type therefore sets the type of the others.
[+ 9007199254740993 1]gives the exact value9007199254740994.[/ 6 3]gives2.[/ 6.0 3.0]gives2.0.
An integer result outside the 64-bit range is an error. The value does not change to a negative number.
[+ 9223372036854775807 1]
Error
Runtime_Failure: Integer addition exceeds the signed 64-bit range.
Arithmetic operators do not change text into a number.
[+ '5' 1]
Error
Runtime_Failure: A number is required, but the value has type string.
Stardust compares an integer with a float exactly. The expression
[> 9007199254740993 9007199254740992.0] is true.
Changing a value type
Use toInt, toFloat, toText, or toBool when an operator needs a
different value type. Each operator accepts one argument.
toInt keeps an integer and changes a boolean to 1 or 0. It also reads
signed decimal integer text.
[toInt '-42']
-42
A float loses its fraction toward zero. NaN, infinity, and values outside the signed 64-bit integer range give an error.
toFloat keeps a float, changes an integer to a float, and reads decimal or
exponent text. The result can lose integer precision. A boolean gives an error.
[toFloat '1e3']
1000.0
toText gives plain text for numbers and booleans. A float without a fraction
gives no decimal point, so [toText 2.0] gives 2. It gives null as the text
null, and gives lists and maps as JSON.
[toText [list 1 true]]
'[1,true]'
toBool accepts a boolean, the exact text true or false, and the integer
1 or 0. Other values give an error.
These operators reject spaces around numeric text and values outside the
applicable range. toInt rejects decimal text such as 4.0.
Use floor, ceil, or round when you must control how a float becomes an
integer. Use format when you must control the text digits.
Cost
The native evaluation reports measured CPU time in 100-nanosecond ticks. The evaluation options use the same unit for the cost limit. Evaluating gives the details.
Types
Stardust calculates the type of the result and the type of each variable from
their use. Each operator sets the types of its arguments and its result.
Stardust changes no type automatically. One argument with a known type
therefore sets the other types. A type that stays unknown becomes any.
Syntax gives the branch operators, the names that you set, the functions, and the literal values.