-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello.lox
More file actions
49 lines (41 loc) · 857 Bytes
/
Copy pathhello.lox
File metadata and controls
49 lines (41 loc) · 857 Bytes
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
// test variabile locale si globale
var global = "global";
{
var local = "local";
print local; // local
print global; // global
}
// test functii si closures
fun makeCounter() {
var count = 0;
fun increment() {
count = count + 1;
return count;
}
return increment;
}
var counter = makeCounter();
print counter(); // 1
print counter(); // 2
print counter(); // 3
// test recursivitate
fun fibonacci(n) {
if (n <= 1) return n;
return fibonacci(n - 1) + fibonacci(n - 2);
}
print fibonacci(10); // 55
// test lambda
var double = fun(x) x * 2;
print double(5); // 10
// test loop cu break si continue
var i = 0;
while (i < 10) {
i = i + 1;
if (i == 3) continue;
if (i == 6) break;
print i; // 1, 2, 4, 5
}
// test variabila nefolosita (ar trebui sa dea warning/eroare)
// {
// var unused = "never used";
// }