Skip to content

Instantly share code, notes, and snippets.

@moxaj
Last active November 7, 2016 22:11
Show Gist options
  • Save moxaj/47e4cd423b856bf206ae93d8780f68fc to your computer and use it in GitHub Desktop.
Save moxaj/47e4cd423b856bf206ae93d8780f68fc to your computer and use it in GitHub Desktop.
(defmacro evaluated [syms & body]
(let [m (into {} (map (juxt identity gensym) syms))]
`(let [~@(mapcat (fn [temp-sym] [temp-sym `(gensym)]) (vals m))]
`(let [~~@(mapcat reverse m)]
~(let [~@(mapcat identity m)]
~@body)))))
(defmacro foo [a b]
`(+ ~a ~a ~b ~b))
(defmacro bar [a b]
(evaluated [a b]
`(+ ~a ~a ~b ~b)))
(foo (do (print "A") 1)
(do (print "B") 2))
;; => prints AABB, returns 6
(bar (do (print "A") 1)
(do (print "B") 2))
;; => prints AB, returns 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment