Skip to content

Instantly share code, notes, and snippets.

@gilbertw1
Created July 29, 2013 21:27
Show Gist options
  • Save gilbertw1/6108019 to your computer and use it in GitHub Desktop.
Save gilbertw1/6108019 to your computer and use it in GitHub Desktop.
->>> Sample Macro
(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