-
Notifications
You must be signed in to change notification settings - Fork 5
Language Cheatsheet
This is a work in progress.
nil
- booleans:
true
orfalse
- numbers: 0 1 2.3 4.5e6 0b111011 0777 0x123 123_456_789
- strings: "Hello world"
- generic values: a, b, c...
- generic symbols: $a, $b, $c
a + b
is an expression
a + b ; c + d
is an expression sequence (also an expression)
; and a newline (also a comma in many contexts) are expression separators
Expression separators are optional, where the expressions are unambiguous. So, a+b; c+d
, a+b c+d
and
a+b
c+d
are equivalent (they are all an expression list).
a = 100 \\ grammar sugar :let(a, 100) \\ Internal form
The symbol a
gets defined in the current evaluation context
if expr exprIfTrue //grammar sugar
else exprIfFalse
:if(&expr &exprIfTrue &exprIfFalse={}) // internal representation
The &
marks an eta-parameter which is passed as-is, without eager-evaluation.
Take the following example:
a = someFunc()
if a > 100 {
print("A is greater than 100:" a)
a = 0 }
else print("A is not big enough")
The {...}
is actually an expression sequence, itself an expression, which is evaluated according with the control flow. This program is equivalent to:
a = someFunc()
:if( a > 100 { print("A is greater than 100:" a) a = 0 } print("A is not big enough"))
or (separators added for readability):
a = someFunc()
:if( a > 100,
{ print("A is greater than 100:" a), a = 0 },
print("A is not big enough")
)
And this is equivalent to:
:let(a, someFunc())
:let(ifTrue, {{print("A is greater than 100:", a=0}})
:let(ifFalse, {{print("A is greater than 100:" a)}} )
:if( a > 100 ifTrue ifFalse)
The second parameter of let
is evaluated eagerly, which "strips" the first pair of {}
, as {expr}
evals to expr
.
more