Created
October 4, 2013 19:18
-
-
Save jcromartie/6831218 to your computer and use it in GitHub Desktop.
A macro that wraps values in a binding form with `future` and transparently `deref` them in the body.
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
(defmacro let-futures | |
[bindings & body] | |
(let [binding-pairs (partition 2 bindings) | |
future-syms (set (map first binding-pairs)) | |
binding-vector (vec (mapcat (fn [[l r]] [l (list 'future r)]) binding-pairs)) | |
body-code (clojure.walk/walk | |
(fn derefify [x] | |
(if (future-syms x) | |
(list 'clojure.core/deref x) | |
(clojure.walk/walk derefify identity x))) | |
identity | |
body)] | |
`(let ~binding-vector ~@body-code))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment