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.
#_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.
[if [> ?age 18] adult minor]
- age
- 21
adult
when and unless each have a condition and one result. when gives the
result when the condition is true.
[when [> ?age 18] adult]
- age
- 21
adult
unless gives the result when the condition is false.
[unless ?blocked send]
- 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.
[cond [< ?n 0] negative [= ?n 0] zero true positive]
- 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.
[let [?a 5 ?b [+ ?a 1]] [* ?a ?b]]
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.
[let [?x 2] [+ ?x 1]]
- x
- 99
3
A plain word in value position stays text.
[let [?name 7] [list name ?name]]
[name 7]
Functions
fn makes a function. It has a list of parameter names and a body. Some
operators use a function directly.
[map [fn [?value] [* ?value 2]] [list 1 2]]
[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.
[let [?double [fn [?value] [* ?value 2]]] [?double 3]]
6
Literal values
list makes a list. Stardust calculates each item, then keeps the results in
order. The empty list is [].
[list 1 2 [+ 1 2]]
[1 2 3]
A map is an ordinary document. Stardust calculates each value in it and keeps each name.
a 1
b [+ 1 1]
{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.
[quote a]
Error
Unsupported_Node: quote is not supported yet