hy.contrib.walk: Add (macroexpand-all)
This function will recursively perform all possible macroexpansions in the supplied form. Unfortunately, it also traverses into quasiquoted parts, where it shouldn't, but it is a useful estimation of macro expansion anyway. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
This commit is contained in:
parent
817b4688d8
commit
fa24042cb0
@ -45,3 +45,11 @@
|
|||||||
"Performs depth-first, pre-order traversal of form. Calls f on each
|
"Performs depth-first, pre-order traversal of form. Calls f on each
|
||||||
sub-form, uses f's return value in place of the original."
|
sub-form, uses f's return value in place of the original."
|
||||||
(walk (partial prewalk f) identity (f form)))
|
(walk (partial prewalk f) identity (f form)))
|
||||||
|
|
||||||
|
(defn macroexpand-all [form]
|
||||||
|
"Recursively performs all possible macroexpansions in form."
|
||||||
|
(prewalk (fn [x]
|
||||||
|
(if (instance? HyExpression x)
|
||||||
|
(macroexpand x)
|
||||||
|
x))
|
||||||
|
form))
|
||||||
|
@ -22,3 +22,7 @@
|
|||||||
(assert (= (walk identity (partial collector acc) walk-form)
|
(assert (= (walk identity (partial collector acc) walk-form)
|
||||||
nil))
|
nil))
|
||||||
(assert (= acc [walk-form]))))
|
(assert (= acc [walk-form]))))
|
||||||
|
|
||||||
|
(defn test-macroexpand-all []
|
||||||
|
(assert (= (macroexpand-all '(with [a b c] (for [d c] foo)))
|
||||||
|
'(with* [a] (with* [b] (with* [c] (do (for* [d c] foo))))))))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user