-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.la
97 lines (72 loc) · 1.86 KB
/
core.la
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
(def identity (# (x) x))
(def select-first (# (x _) x))
(def select-second (# (_ y) y))
(def true (# (x _) x))
(def false (# (_ y) y))
(def not (# (x) (x false true)))
(def and (# (x y) (x y false)))
(def or (# (x y) (x true y)))
(def bool-equal? (# (x y) (x y (not y))))
(def if (# (predicate success fail) ((predicate success fail))))
(def succ (# (n) (# (s) (s false n))))
(def 0? (# (n) (n true)))
(def pred (# (n) ((0? n) n (n false))))
(def 0 identity)
(def 1 (succ 0))
(def 2 (succ 1))
(def 3 (succ 2))
(def 4 (succ 3))
(def 5 (succ 4))
(def 6 (succ 5))
(def 7 (succ 6))
(def 8 (succ 7))
(def 9 (succ 8))
(def 10 (succ 9))
(def 11 (succ 10))
(def 12 (succ 11))
(def 13 (succ 12))
(def 14 (succ 13))
(def 15 (succ 14))
(def 16 (succ 15))
(def 17 (succ 16))
(def 18 (succ 17))
(def 19 (succ 18))
(def 20 (succ 19))
(def + (# (x y)
(if (0? y)
(# () x)
(# () (+ (succ x) (pred y))))))
(def - (# (x y)
(if (0? y)
(# () x)
(# () (- (pred x) (pred y))))))
(def * (# (x y)
(if (0? y)
(# () 0)
(# () (+ x (* x (pred y)))))))
(def __/ (# (x y)
(if (> y x)
(# () 0)
(# () (succ (__/ (- x y) y))))))
(def / (# (x y)
(if (0? y)
(# () 0)
(# () (__/ x y)))))
(def ^ (# (n pow)
(if (0? pow)
(# () 1)
(# () (* n (^ n (pred pow)))))))
(def abs-diff (# (x y) (+ (- x y) (- y x))))
(def = (# (x y) (0? (abs-diff x y))))
(def > (# (x y) (not (0? (- x y)))))
(def >= (# (x y) (0? (- y x))))
(def < (# (x y) (> y x)))
(def <= (# (x y) (>= y x)))
(def __% (# (x y)
(if (< x y)
(# () x)
(# () (__% (- x y) y)))))
(def % (# (x y)
(if (0? y)
(# () x)
(# () (__% x y)))))