Created
December 20, 2011 01:09
-
-
Save AlexBaranosky/1499725 to your computer and use it in GitHub Desktop.
macroexpand-scan / macroexpand-reductions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn macroexpand-scan | |
([form] | |
(macroexpand-scan form [])) | |
([form results] | |
(let [expanded (macroexpand-1 form)] | |
(if (= expanded form) | |
results | |
(recur expanded (conj results expanded)))))) | |
;; Example | |
(defmacro a [s] `(defn ~(symbol s) [] ~s)) | |
(macroexpand-scan `(a "f")) | |
; => [(clojure.core/defn f [] "f") | |
; (def f (clojure.core/fn ([] "f")))] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! Love the way you identified the higher-order function latent within this function. I think that's a great way to look at Clojure, always trying to extract out the higher order function in things, makes everything uber-composable. Thanks. See: https://gist.github.com/1501358 ,
(def macroexpand-scan (partial steady-state macroexpand-1))