-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.dl
61 lines (53 loc) · 1.01 KB
/
test.dl
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
use "std.dl";
/* Standard recursive fibonacci definition */
let fibo <- { x |
cond
| x == 0 -> 1;
| x == 1 -> 1;
| otherwise -> fibo (x - 1) + fibo (x - 2);
;
};
/* Prettier, less deeply recursive fibonacci */
let fib <- { a b x |
cond
| x == 0 -> a;
| otherwise -> fib b (a + b) (x - 1);
;
};
/* Currying is available */
let flatfibo <- fib 1 1;
let tracefibo <- { a b x |
cond
| x == 0 -> print! "exiting";
;
cond
| x == 0 -> a;
| otherwise ->
print! "going deeper";
tracefibo b (a + b) (x - 1);
;
};
/* Test for scope */
let a <- "outer";
let f! <- { ! |
let showA! <- { ! | print! a; };
showA!;
let a <- "inner";
showA!;
};
/* Mutual recursion */
let odd <- { x |
cond
| x == 0 -> false;
| otherwise -> even (x - 1);
;
},
even <- { x |
cond
| x == 0 -> true;
| otherwise -> odd (x - 1);
;
};
/* As useful as expected, but proves TCE works. */
let loop_forever! <- { ! | loop_forever!; };
let hello! <- { ! | forever! { ! | print! "Hello!"; }; };