This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
052num.wart
113 lines (83 loc) · 1.69 KB
/
052num.wart
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
110
111
112
113
let ($+) (+)
def! (+ ... args)
(reduce ($+) args 0)
let ($-) (-)
def! (- ... args)
(reduce ($-) args)
let ($*) (*)
def! (* ... args)
(reduce ($*) args 1)
let ($/) (/)
def! (/ ... args)
(reduce ($/) args)
let ($%) (%)
def! (% ... args)
(reduce ($%) args)
mac ++n
`(zap! (+) ,n 1)
mac --n
`(zap! (-) ,n 1)
def (- n ... rest) :case no.rest
(- 0 n)
let ($<) (<)
def (< ... args) :case ($< 2 len.args)
(and (all (fn((x y)) (x < y))
pairwise.args)
last.args)
def (> ... args)
(aand (all (fn((x y)) (y < x))
pairwise.args)
(or last.args it))
def (<= ... args)
(aand (none predicate.nil args)
(none (fn((x y)) (y < x))
pairwise.args)
(or last.args it))
def (>= ... args)
(aand (none predicate.nil args)
(none (fn((x y)) (x < y))
pairwise.args)
(or last.args it))
def (min ... args)
(best (<) args)
def (max ... args)
(best (>) args)
def (< scorer ... rest) :case (and fn?.scorer no.rest)
(fn(x y)
(aif (scorer.x < scorer.y)
y
false))
def (> scorer ... rest) :case (and fn?.scorer no.rest)
(fn(x y)
(aif (scorer.x > scorer.y)
y
false))
def (zero? n)
(n = 0)
def (divides nr dr)
(zero? nr%dr)
def (even? n)
(divides n 2)
alias odd? ~even?
def (sum seq)
(+ @seq)
def (product seq)
(* @seq)
def (abs n)
if (n < 0) -n :else n
mac (add! x|to y)
`(,x <- (+ ,x ,y))
mac! (a += b)
`(add! ,a ,b)
mac (sub! x|from y)
`(,x <- (- ,x ,y))
mac! (a -= b)
`(sub! ,a ,b)
mac (mul! x y|by)
`(,x <- (* ,x ,y))
mac! (a *= b)
`(mul! ,a ,b)
mac (div! x y|by)
`(,x <- (/ ,x ,y))
mac! (a /= b)
`(div! ,a ,b)