-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.lattice
93 lines (72 loc) · 1.62 KB
/
test.lattice
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Commands are inputs for pipes
# types: int, float, string, block
mod new_module # Declares a module in the path
use new_module::a # Statement to make function available in this file
use new_module::{b, c} # Statement to make function available in this file
let a = 2
let b = 3
let c = $a + $b
$a || $b
$a or $b
$a && $b
$a and $b
# Calling a command
command val --flag -f
let a = command val --flag -f
| command b # This comment gets ignored
| command c
alias a = command val --flag -f
# This is a block and it cannot be stored
{
1 + 2
}
# But it has a return value and can be stored
let a = {
1 + 2
}
# This is a closure and can be stored and used in commands
let d = {||
}
let b = command a | command c | command $d
let b = (command a | command c | command d)
let c = "this is a string"
let d = """this is a "raw" string"""
let e = f"this: {$a}"
let f = f"""this: {$a}"""
# This is a comment
# This becomes a list of strings
let e = [bare words are strings]
$e.0 # returns bare
# This becomes a table
let f = [[a, b]; [1 2] [3 4]]
$f.0 # returns [1 2] (row)
$f.a # returns [1 3] (col)
# a function definition
def inner(a: int, c: string) -> string {
# Single if is an statement
if (true) {
return
}
# if/else is an expression and both should return the same value type
let a = if true {
1
} else {
2
}
# Return type should match def output
"value"
}
'name while true {
if true {
break 'name
}
}
# for loops over elements in list
for i in 1..20 {
if (i == 3) {
continue
}
if (i > 10) {
break
}
}