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:

TRON85 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 2Atxt "*"
0602 03000000000000 00i64 3
0F02 04000000000000 00i64 4
180E 15 00 0700 030000 00 04000000 060000 00 0F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @6 → @F
2D1C 2Btxt "+"
2F02 02000000000000 00i64 2
380E 15 00 0700 030000 00 2D000000 2F0000 00 18000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @2D → @2F → @18
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 0E000000000000 00i64 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.

TRON371 B
Offset (hex)Bytes (hex)Meaning
00054 52 4F 4Emagic TRON
0043C 616765txt "age"
00802 24000000000000 00i64 36
0110F 0A 04000000 0800 0000map leaf, size 10: @4 → @8
01B4C 726F6C65txt "role"
0208C 656E67696E6565 72txt "engineer"
0290F 0A 1B000000 2000 0000map leaf, size 10: @1B → @20
0334C 6E616D65txt "name"
0383C 416461txt "Ada"
03C0F 0A 33000000 3800 0000map leaf, size 10: @33 → @38
04607 12 00910000 1100 0000 29000000 3C00 0000map branch, size 18, depth 0 (root), slots 8, 12, 15: @11 → @29 → @3C
0585C 236C696E6Btxt "#link"
05E5C 235F616461txt "#_ada"
0640F 0A 58000000 5E00 0000map leaf, size 10: @58 → @5E
06E3C 616765txt "age"
07202 29000000000000 00i64 41
07B0F 0A 6E000000 7200 0000map leaf, size 10: @6E → @72
0856C 6D656E746F72txt "mentor"
08C0F 0A 85000000 6400 0000map leaf, size 10: @85 → @64
0964C 726F6C65txt "role"
09B8C 656E67696E6565 72txt "engineer"
0A40F 0A 96000000 9B00 0000map leaf, size 10: @96 → @9B
0AE4C 6E616D65txt "name"
0B33C 426F62txt "Bob"
0B70F 0A AE000000 B300 0000map leaf, size 10: @AE → @B3
0C107 16 00990000 7B00 0000 8C000000 A400 0000 B7000000map branch, size 22, depth 0 (root), slots 8, 11, 12, 15: @7B → @8C → @A4 → @B7
0D73C 616765txt "age"
0DB02 1D000000000000 00i64 29
0E40F 0A D7000000 DB00 0000map leaf, size 10: @D7 → @DB
0EE4C 726F6C65txt "role"
0F38C 64657369676E65 72txt "designer"
0FC0F 0A EE000000 F300 0000map leaf, size 10: @EE → @F3
1064C 6E616D65txt "name"
10B2C 4379txt "Cy"
10E0F 0A 06010000 0B01 0000map leaf, size 10: @106 → @10B
11807 12 00910000 E400 0000 FC000000 0E01 0000map branch, size 18, depth 0 (root), slots 8, 12, 15: @E4 → @FC → @10E
12A4C 235F6379txt "#_cy"
12F0F 0A 2A010000 1801 0000map leaf, size 10: @12A → @118
1395C 235F626F62txt "#_bob"
13F0F 0A 39010000 C100 0000map leaf, size 10: @139 → @C1
1495C 235F616461txt "#_ada"
14F0F 0A 49010000 4600 0000map leaf, size 10: @149 → @46
15907 12 80210000 2F01 0000 3F010000 4F01 0000map branch, size 18, depth 0 (root), slots 7, 8, 13: @12F → @13F → @14F

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.

TRON47 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 2Btxt "+"
062C 3F78txt "?x"
0902 01000000000000 00i64 1
120E 15 00 0700 030000 00 04000000 060000 00 09000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @6 → @9
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 2A000000000000 00i64 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.

TRON68 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
042C 6966txt "if"
0702 00000000000000 00i64 0
10CC 7A65726F2D6973 2D74727565txt "zero-is-true"
1D5C 6E65766572txt "never"
230E 19 00 0F00 040000 00 04000000 070000 00 10000000 1D0000 00array leaf, size 25, shift 0, bitmap 000F, count 4 (root): @4 → @7 → @10 → @1D
TRON25 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
04CC 7A65726F2D6973 2D74727565txt "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 value 9007199254740994.
  • [/ 6 3] gives 2. [/ 6.0 3.0] gives 2.0.

An integer result outside the 64-bit range is an error. The value does not change to a negative number.

TRON53 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 2Btxt "+"
0602 FFFFFFFFFFFFFF 7Fi64 9223372036854775807
0F02 01000000000000 00i64 1
180E 15 00 0700 030000 00 04000000 060000 00 0F000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @6 → @F

Error

Runtime_Failure: Integer addition exceeds the signed 64-bit range.

Arithmetic operators do not change text into a number.

TRON46 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
041C 2Btxt "+"
061C 35txt "5"
0802 01000000000000 00i64 1
110E 15 00 0700 030000 00 04000000 060000 00 08000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @6 → @8

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.

TRON39 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 746F496E74txt "toInt"
0A3C 2D3432txt "-42"
0E0E 11 00 0300 020000 00 04000000 0A0000 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @4 → @A
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0402 D6FFFFFFFFFFFF FFi64 -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.

TRON41 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
047C 746F466C6F6174txt "toFloat"
0C3C 316533txt "1e3"
100E 11 00 0300 020000 00 04000000 0C0000 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @4 → @C
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
0403 0000000000408F 40f64 1000

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.

TRON72 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
044C 6C697374txt "list"
0902 01000000000000 00i64 1
1209bit true
130E 15 00 0700 030000 00 04000000 090000 00 12000000array leaf, size 21, shift 0, bitmap 0007, count 3 (root): @4 → @9 → @12
286C 746F54657874txt "toText"
2F0E 11 00 0300 020000 00 28000000 130000 00array leaf, size 17, shift 0, bitmap 0003, count 2 (root): @28 → @13
TRON21 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
048C 5B312C74727565 5Dtxt "[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.

Run it

build · program evaluate.