2017-06-26 12:15:03 +03:00
|
|
|
(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
|
2017-07-13 14:08:45 +03:00
|
|
|
(quote set!) (list (quote ref) (car settings))
|
2017-06-26 12:15:03 +03:00
|
|
|
(list (quote Int.+)
|
|
|
|
(car settings)
|
|
|
|
(if (= 4 (count settings)) ;; optional arg for step
|
|
|
|
(car (cdr (cdr (cdr settings))))
|
|
|
|
1)))))))
|
2017-06-29 18:05:34 +03:00
|
|
|
|
|
|
|
(defmacro refstr [x]
|
|
|
|
(list (quote ref)
|
|
|
|
(list (quote str) x)))
|