Syntax

In most lists, the first item is an operator. Stardust calculates the arguments first. Then it applies the operator to them. The names on this page control which arguments Stardust calculates or give a value.

An expression produces a value. A literal expression, such as 5, adult or true, produces itself. A variable expression starts with ? and reads a named value.

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}

Branches

if has a condition, a result for true, and an optional result for false. Only null and false are false. Stardust calculates only the branch that it uses. Without the last argument, a false condition gives null.

dust29B
[if [> ?age 18] adult minor]
Result / 5B
age
21
adult

when and unless each have a condition and one result. when gives the result when the condition is true.

dust25B
[when [> ?age 18] adult]
Result / 5B
age
21
adult

unless gives the result when the condition is false.

dust23B
[unless ?blocked send]
Result / 4B
blocked
false
send

In the other case, each one gives null. Neither operator accepts a second result.

cond has pairs of condition and result. It gives the result of the first true condition.

dust53B
[cond [< ?n 0] negative [= ?n 0] zero true positive]
Result / 8B
n
5
positive

and and or stop at the first argument that sets the answer. Both give true or false.

Variables that you set

let sets variables for the rest of the expression. Variable names and values come in pairs. Each binding and reference uses ?name, and each value can read the variables above it.

dust35B
[let [?a 5 ?b [+ ?a 1]] [* ?a ?b]]
Result / 2B
30

The same spelling declares and reads a variable. If let or fn does not declare the variable, the caller must give its value. A local declaration with the name of a caller variable replaces that variable for the rest of the expression.

dust22B
[let [?x 2] [+ ?x 1]]
Result / 1B
x
99
3

A plain word in value position stays text.

dust34B
[let [?name 7] [list name ?name]]
Result / 8B
[name 7]

Functions

fn makes a function. It has a list of parameter names and a body. Some operators use a function directly.

dust44B
[map [fn [?value] [* ?value 2]] [list 1 2]]
Result / 5B
[2 4]

Each parameter uses ?name to declare a variable. The parameter names must be different from each other. A reference in the function body starts with ?. A function has a maximum of eight parameters. The body can also use each variable from a let around it.

You can also give a function a name with let. Put its variable reference first in a list. Stardust then calculates the function with the other items as its arguments.

dust55B
[let [?double [fn [?value] [* ?value 2]]] [?double 3]]
Result / 1B
6

Literal values

list makes a list. Stardust calculates each item, then keeps the results in order. The empty list is [].

dust19B
[list 1 2 [+ 1 2]]
Result / 7B
[1 2 3]

A map is an ordinary document. Stardust calculates each value in it and keeps each name.

dust14B
a 1
b [+ 1 1]
Result / 10B
{a 1
 b 2}

Text, numbers, true, false and null are values. Stardust gives each one without a change. A list whose first item is not text is also a list of values. list makes this clear to the reader.

Some other languages use quote to stop the evaluation of a list. Stardust reserves the name and rejects it. A plain word is already text, so a program needs no operator for this.

dust10B
[quote a]

Error

Unsupported_Node: quote is not supported yet

Run it

build · program evaluate.