blob: aca5c3649258f7a2f6d82929df48bc0d15cb3504 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
; Basic if expressions.
if true "hello"
; These can produce values and the result bound to a name.
let a = if (2 + 2 >= 4) 42
; We support a single if expression.
let b = if (0xff == 0x32) "hello" else "world"
; ... but these can compound on each other
if 1 < 2 6
else if 1 > 2 7
else 8
; A block is an expression, and if raise the scope level regardless if a block
; is used or not.
if true != false {
let a = "yo"
}
; Match cases should only apply to literal values, for example `case 1 + 2`
; isn't allowed. They should generally convert to a lookup table.
match a {
case 8 = "hello"
case 9 = "world"
else = "what"
}
; Enums are integers with values that increase automatically or that can be set
; with a constexpr.
enum flags {
node_add = 1 << 0
node_sub = 1 << 1
node_div = 1 << 2
node_mul
}
let f:flags = flags.node_add
; No need to qualify enum fields inside match-case.
match f {
case node_add = "adding something..."
case node_add = "subbing something..."
else = "default case"
}
; Conditional `cond` statements are syntactic sugar for a chain of if-else
; statements.
let msg:str = cond {
a == 1 = "hello"
a != 2 = "world"
else = "what"
}
|