Created
June 7, 2012 15:06
-
-
Save megakorre/2889294 to your computer and use it in GitHub Desktop.
aggr a macro for reduce comprihension*
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
(defn compile-aggr [binding code] | |
(let [[scoped expression & r] binding] | |
(when (and scoped (not expression)) | |
(throw (new Exception "aggr needs a even number of parameters"))) | |
(if scoped | |
`(reduce | |
(fn [a# b#] (let [~scoped [a# b#]] ~(compile-aggr r code))) | |
~expression) | |
`(do ~@code)))) | |
(defmacro aggr | |
[binding & code] | |
(compile-aggr binding code)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment