Created
May 5, 2012 07:02
-
-
Save yuanmai/2600546 to your computer and use it in GitHub Desktop.
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
;; 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