This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
/
036control.wart
110 lines (87 loc) · 1.87 KB
/
036control.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
mac do1 body
`(ret $ret ,car.body
,@cdr.body)
mac between(before after/and . body)
`(do1
(do ,before ,@body)
,after)
mac before(cleanup . body)
`(do1
(do ,@body)
,cleanup)
mac when(cond . body)
`(if ,cond
(do ,@body))
mac unless(cond . body)
`(if !,cond
(do ,@body))
mac iflet(var expr . branches)
if !branches
expr
`(let $tmp ,expr
(if $tmp
(let ,var $tmp
,car.branches)
,(if cdr.branches
`(iflet ,var ,@cdr.branches))))
mac aif(expr . branches)
`(iflet it ,expr ,@branches)
mac whenlet(var test . body)
`(iflet ,var ,test
(do ,@body))
mac awhen(test . body)
`(whenlet it ,test
,@body)
mac aand args
(if
!args
1
~cdr.args
car.args
:else
`(aif ,car.args
(aand ,@cdr.args)))
mac while(test . body)
`(when ,test
,@body
(while ,test
,@body))
mac whilet(var test . body)
`(let ,var nil
(while (= ,var ,test)
,@body))
mac awhile(test . body)
`(whilet it ,test
,@body)
mac for(var start test update . body)
`(let ,var ,start
(while ,test
,@body
,update))
mac each(var expr . body)
`(for $i (as list ,expr) $i (zap cdr $i)
(let ,var car.$i
,@body))
mac on(var expr . body)
`(for ($i index) (list ,expr 0) $i (do (zap cdr $i) ++.index)
(let ,var car.$i
,@body))
mac forlen(var expr . body)
`(for ,var 0 (< ,var len.,expr) ++.,var
,@body)
mac repeat(n . body)
`(for $i 0 (< $i ,n) ++.$i
,@body)
mac repeat(n . body) :case (iso :forever n)
`(while 1 ,@body)
def andf fs
(fn args
(let sub (afn(fs)
(if
!fs
1
~cdr.fs
(car.fs @args)
:else
(and (car.fs @args) (self cdr.fs))))
(sub fs)))