-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstd.dl
More file actions
101 lines (82 loc) · 1.92 KB
/
Copy pathstd.dl
File metadata and controls
101 lines (82 loc) · 1.92 KB
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
/* The "Standard Library" */
let true <- {#true};
let false <- {#false};
let empty <- {#empty};
let otherwise <- true;
/* IO */
let print! <- { ! s | {#print} s; };
let read! <- { ! | {#read} 0; };
/* Boolean. NOT short-circuited. */
let || <- { x y |
cond
| x -> true;
| otherwise -> y;
;
};
let && <- { x y |
cond
| x -> y;
| otherwise -> false;
;
};
let not <- { x |
cond
| x -> false;
| otherwise -> true;
;
};
/* Arithmetics */
let + <- { x y | {#add} x y; };
let - <- { x y | {#sub} x y; };
let * <- { x y | {#mul} x y; };
let / <- { x y | {#fdiv} x y; };
let % <- { x y | {#mod} x y; };
/* Comparisons */
let == <- { x y | {#eq} x y; };
let != <- { x y | not (x == y); };
let > <- { x y | {#gt} x y; };
let >= <- { x y | (x == y) || (x > y); };
let < <- { x y | not (x >= y); };
let <= <- { x y | not (x > y); };
/* Bang! helpers */
let forever! <- { ! command! |
command!;
forever! command!;
};
let flip <- { f x y | f y x; };
/* List functions */
let :: <- { car cdr | {#cons} car cdr; };
let head <- { l | {#head} l; };
let tail <- { l | {#tail} l; };
let foldl <- { f a l |
cond
| l == empty -> a;
| otherwise -> foldl f (f a (head l)) (tail l);
;
};
let reverse <- foldl (flip (::)) empty;
let map_ <- { a f l |
cond
| l == empty -> reverse a;
| otherwise -> map_ (f (head l) :: a) f (tail l);
;
}, map <- map_ empty;
let range_ <- { acc from to |
cond
| from == to -> reverse acc;
| otherwise -> range_ (from :: acc) (from + 1) to;
;
}, range <- range_ empty;
let filter_ <- { a p l |
cond
| l == empty -> reverse a;
| p (head l) -> filter_ (head l :: a) p (tail l);
| otherwise -> filter_ a p (tail l);
;
}, filter <- filter_ empty;
let length <- foldl ((+) 1) 0;
/* Functional helpers */
let =>> <- { v f | f v; };
let >> <- { f g x | g (f x); };
let . <- { f g x | f (g x); };
let $ <- { f v | f v; };