-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprelude.stutter
More file actions
59 lines (38 loc) · 1.63 KB
/
prelude.stutter
File metadata and controls
59 lines (38 loc) · 1.63 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
def [fun] (\ [f body] [deepdef (first f) (\ (tail f) body)])
fun [+ a b] [iadd a b]
fun [- a b] [isub a b]
fun [* a b] [imul a b]
fun [/ a b] [idiv a b]
fun [bool a] [if a [0] [1]]
fun [== a b] [not (bool (cmp a b))]
fun [/= a b] [bool (cmp a b)]
fun [< a b] [== (cmp a b) -1]
fun [> a b] [== (cmp a b) 1]
fun [<= a b] [/= (cmp a b) 1]
fun [>= a b] [/= (cmp a b) -1]
fun [and a b] [* a b]
fun [or a b] [if (== a b) [1] [a]]
fun [not a] [- 1 a]
fun [map f lst] [if (empty lst) [: (f (head lst)) (map f (tail lst))] [lst]]
fun [foldr f initial lst] [if (empty lst) [f (head lst) (foldr f initial (tail lst))] [initial]]
def [list] (\ [... collector] [collector])
fun [max a b] [if (> a b) [b] [a]]
fun [min a b] [if (< a b) [b] [a]]
fun [zip a b] [if (or (empty a) (empty b)) [: (list (head a) (head b)) (zip (tail a) (tail b))] [[]]]
fun [++ a b] [if (empty a) [++ (init a) (: (last a) b)] [b]]
def [flip] (\ [f a b] [f b a])
def [length] (foldr (\ [a b] [+ b 1]) 0)
fun [filter predicate lst] [foldr (\ [a b] [if (predicate a) [b] [: a b]]) [] lst]
fun [chain ignored returnvalue] [returnvalue]
fun [range from to] [if (>= from to) [: from (range (+ from 1) to)] [[]]]
fun [irange from to] [if (> from to) [: from (irange (+ from 1) to)] [[]]]
fun [strappend a b] [fexpr-str (++ (str-fexpr a) (str-fexpr b))]
def [strconcat] (foldr strappend "")
fun [reverse lst] [foldr (\ [a b] [++ b (list a)]) [] lst]
fun [parseChrs chrs] [if (empty chrs) [+ (- (head chrs) 48) (* 10 (parseChrs (tail chrs)))] [0] ]
fun [parse str] [parseChrs (reverse (str-fexpr str)) ]
fun [isNumber charcode] [
(and
(<= charcode 57)
(>= charcode 48)
)]