Created
July 29, 2013 21:27
-
-
Save gilbertw1/6108019 to your computer and use it in GitHub Desktop.
->>> Sample Macro
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 replace-if-underscore [element val] | |
(if (= element '_) | |
val | |
element)) | |
(defn replace-underscores [form val] | |
(map #(replace-if-underscore % val) form)) | |
(defn convert-forms [val [next-form & other-forms]] | |
(if (nil? next-form) | |
val | |
(let [next-val (gensym)] | |
`(let [~next-val ~(replace-underscores next-form val)] | |
~(convert-forms next-val other-forms))))) | |
(defmacro ->>> [init & forms] | |
(convert-forms init forms)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment