forked from carp-lang/Carp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMacros.carp
36 lines (33 loc) · 948 Bytes
/
Macros.carp
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
(defdynamic cond-internal [xs]
(if (= (count xs) 0)
(list)
(if (= (count xs) 2)
(list)
(if (= (count xs) 1)
(car xs)
(list
(quote if)
(car xs)
(car (cdr xs))
(cond-internal (cdr (cdr xs))))))))
(defmacro cond [:rest xs]
(cond-internal xs))
(defmacro for [settings body] ;; settings = variable, from, to, <step>
(list
(quote let)
(array (car settings) (car (cdr settings)))
(list
(quote while)
(list (quote Int.<) (car settings) (car (cdr (cdr settings))))
(list (quote do)
body
(list
(quote set!) (list (quote ref) (car settings))
(list (quote Int.+)
(car settings)
(if (= 4 (count settings)) ;; optional arg for step
(car (cdr (cdr (cdr settings))))
1)))))))
(defmacro refstr [x]
(list (quote ref)
(list (quote str) x)))