Created
April 25, 2013 12:34
-
-
Save guv/5459364 to your computer and use it in GitHub Desktop.
Parallel let macro
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 plet [bindings & body] | |
(let [bindings (partition-all 2 bindings) | |
destruct-exprs (map first bindings) | |
expressions (map second bindings) | |
vars (repeatedly (count bindings) gensym)] | |
`(let [~@(mapcat (fn [var expr] `[~var (future ~expr)]) vars expressions) | |
~@(mapcat (fn [destr var] `[~destr (deref ~var)]) destruct-exprs vars)] | |
~@body))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment