-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomlanguage.txt
146 lines (80 loc) · 2.52 KB
/
customlanguage.txt
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# this is a comment
// ---- VARIABLES ----
set x = 1
const pi = 3.14
let y # by default its value is undefined
y = 5
// ---- LISTS ----
set list = [-1, 0, 1, 2, 3]
list.foreach(i => print(i))
list.map(#*2) // => -2 0 2 4 6
list.filter(# > 0) // => 1 2 3
list.acc(elem, acc => elem + acc) // list.acc(_ + #) => 5
list.pop(-1) // removes element by index
list = myList[:-1] // list slicing
list.append(4) // adds 4 to the end of the list
list.remove(0) // removes all elements equal to 0
list.clear() // []
// ---- LOOPS ----
for i from 0 to 5 step 2:
print(i)
for elem in list;
print(elem)
while x++ > 10:
print("!")
until x++
print("\n")
loop(10):
print("!")
// ---- MAPS ----
map = {1:'a', 2:'b'}
map = list => list2 // list -> list2 for every key-value pair
// ---- FUNCTIONS AND CONDITIONALS ----
fn say_hello(x):
print("hello #x") // hello world
fn print_something(x) => print(x)
fn check_ifs(x):
return if (x % 2 == 0) true elsif(x == -1) false else x++ == 2
fn check_switch(x):
set x = switch(x):
# % 2 == 0 -> true
-1 -> false
else -> #++ == 2
return x
int one_liner(z) => z == 0 ? -1 : z
// ---- LIST COMPREHENSIONS ----
fn generate_list => [(1..5)*2] // [2,4,6,8,10] short map
fn another_list => [(1..5) % 2 == 0] // [2,4] short filter
fn cond_list => [(1..5) % 2 == 0 ? # : 0] // [0,2,0,4,0] short map with condition
fn accumulate_list => [(1..5) => _ + #] // [15] short accumulate
set generateMap = {(1..5): ('a'..'e')} // {1:a, 2:b, 3:c, 4:d, 5:e}
set cartesianProduct = (1..5) * ('a'..'e') // every possible combination
set emptyArray = [0] * 5 // [0, 0, 0, 0, 0]
// ---- CLASSES ----
class MyClass(int y) => ParentClass:
let static occurrences
let name
fn repr():
return "#y"
override MyClass.repr() => "|#y|"
// ---- DESTRUCTURING AND LAMBDAS ----
set x, y, z = ["a", true, 5]
set start, *_ = [1, 4, 3, 8] // 1, [4,3,8]
set *_, end = ["r", "g", "b"] // [r,g], b
start, *_, (last_word_first_letter, *_) = ["Hi", "How", "are", "you?"]
print(last_word_first_letter) # prints "y"
set x,y = (1,2,3) // tuple destructuring, x = 1, y = 2
set create_vector = (x,y) => Vector(x,y) // lambda function
set vector2 = create_vector(x,y)
fn print() => 'num: 1'
fn do_it(str, fn)
ret fn(str)
foreach i in list
log(i)
set input = in('Enter a number:')
? x > y : print("x is greater than y")
x = "hello"
match x with
"hello": print("Hello World")
"bye" : print("Goodbye")
_ : print("I don't understand")