Reimplement _with and _for as functions

This commit is contained in:
Kodi Arfer 2017-12-30 19:39:15 -05:00
parent 1e4ad3167b
commit b81585eaba

View File

@ -43,7 +43,7 @@ be associated in pairs."
other-kvs))]))))
(defmacro _with [node args &rest body]
(defn _with [node args body]
(if (not (empty? args))
(do
(if (>= (len args) 2)
@ -51,7 +51,7 @@ be associated in pairs."
(setv p1 (.pop args 0)
p2 (.pop args 0)
primary [p1 p2])
`(~node [~@primary] (_with ~node ~args ~@body)))
`(~node [~@primary] ~(_with node args body)))
`(~node [~@args] ~@body)))
`(do ~@body)))
@ -64,7 +64,7 @@ Shorthand for nested with* loops:
(with* [x foo]
(with* [y bar]
baz))."
`(_with with* ~args ~@body))
(_with 'with* args body))
(defmacro with/a [args &rest body]
@ -75,7 +75,7 @@ Shorthand for nested with/a* loops:
(with/a* [x foo]
(with/a* [y bar]
baz))."
`(_with with/a* ~args ~@body))
(_with 'with/a* args body))
(defmacro cond [&rest branches]
@ -108,7 +108,7 @@ used as the result."
root)))
(defmacro _for [node args &rest body]
(defn _for [node args body]
(setv body (list body))
(if (empty? body)
(macro-error None "`for' requires a body to evaluate"))
@ -131,7 +131,7 @@ used as the result."
Args may contain multiple pairs, in which case it executes a nested for-loop
in order of the given pairs."
`(_for for* ~args ~@body))
(_for 'for* args body))
(defmacro for/a [args &rest body]
@ -139,7 +139,7 @@ in order of the given pairs."
Args may contain multiple pairs, in which case it executes a nested for/a-loop
in order of the given pairs."
`(_for for/a* ~args ~@body))
(_for 'for/a* args body))
(defmacro -> [head &rest rest]