-
Notifications
You must be signed in to change notification settings - Fork 4
/
sample.fail
executable file
·109 lines (89 loc) · 1.54 KB
/
sample.fail
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
print "\nFibonacci (first 21):";
var a = 0;
var b = 1;
while (a < 10000) {
print a;
var temp = a;
a = b;
b = temp + b;
}
fun sayHi(first, last) {
print "Hi, " + first + " " + last + "!";
}
sayHi("Dear", "Reader");
print "\nAgain fibonacci, but recursive:";
fun fibonacci(n) {
if (n <= 1) return n;
return fibonacci(n - 2) + fibonacci(n - 1);
}
for (var i = 0; i < 21; i = i + 1) {
print fibonacci(i);
}
print "\nLocal function:";
fun makeCounter() {
var i = 0;
fun count() {
i = i + 1;
print i;
}
return count;
}
var counter = makeCounter();
counter(); // "1".
counter(); // "2".
print "\nClosure:";
fun makePoint(x, y) {
fun closure(method) {
if (method == "x") return x;
if (method == "y") return y;
print "unknown method " + method;
}
return closure;
}
var point = makePoint(2, 3);
print point("x"); // "2".
print point("y"); // "3".
print "\nLambda:";
fun thrice(fn) {
for (var i = 1; i <= 3; i = i + 1) {
fn(i);
}
}
thrice(fun (a) {
print a;
});
print "\nbinding test:";
var a = "global";
{
fun showA() {
print a;
}
showA();
var a = "block";
showA();
}
{
var notUsed = "x";
print "notused";
}
print "\nTesting class:";
class DevonshireCream {
serveOn() {
return "Scones";
}
}
print DevonshireCream;
print (5 - (3 - 1)) + -1;
print "\nInheritance:";
class Doughnut {
cook() {
print "Fry until golden brown.";
}
}
class BostonCream < Doughnut {
cook() {
super.cook();
print "Pipe full of custard and coat with chocolate.";
}
}
BostonCream().cook();