-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.lox
79 lines (57 loc) · 1.16 KB
/
example.lox
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
print "Nearly-complete example";
print "";
print "Declare a as 4";
var a = 4;
print "Assignment is an expression of value the assigned value, here 8";
print a = 8;
print "";
{
print "Enter block";
print "Shadow a with 12";
var a = 12;
print "Here a is now:";
print a;
}
print "Leave block";
print "";
print "Now a is back to:";
print a;
print "";
print "Is 1+1 < 1 ?";
if (1+1 < 1)
print "Yes, 1+1 < 1";
else
print "No, 1+1 >= 1";
"This is dead code";
var forty_two = (3+3) * 8 - 6;
var hello = "Hello, ";
var world = "World !";
print "";
print "hi" or 2; // "hi"
print nil or "yes"; // "yes"
print "hi" and 2; // 2
print nil and "yes";// nil
print "";
print "We got concatenation, too:";
print hello + world;
print "";
print "The answer to (3+3) * 8 - 6 is:"; print forty_two;
print "";
fun factorial(n) {
var acc = 1;
for (var i = 1; i <= n; i = i + 1) {
acc = acc * i;
}
print acc;
}
print "The factorials of 169, 170 and 171 are:";
print "";
var A = clock();
factorial(169);
factorial(170);
factorial(171);
var B = clock();
print "That last one's quite big ! Seconds taken to compute:";
print B - A;
print "";
print "Yeah who uses seconds";