Skip to content

Instantly share code, notes, and snippets.

@yuanmai
Created May 5, 2012 07:02
Show Gist options
  • Save yuanmai/2600546 to your computer and use it in GitHub Desktop.
Save yuanmai/2600546 to your computer and use it in GitHub Desktop.
;; from http://www.learningclojure.com/2010/09/astonishing-macro-of-narayan-singhal.html
(defmacro def-let
"like let, but binds the expressions globally."
[bindings & more]
(let [let-expr (macroexpand `(let ~bindings))
names-values (partition 2 (second let-expr))
defs (map #(cons 'def %) names-values)]
(concat (list 'do) defs more)))
;; from http://blog.gaz-jones.com/2012/02/04/debug_let.html
(defmacro dlet [bindings & body]
`(let [~@(mapcat (fn [[n v]]
(if (or (vector? n) (map? n))
[n v]
[n v '_ `(println (name '~n) " : " ~v)]))
(partition 2 bindings))]
~@body))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment