Skip to content

Instantly share code, notes, and snippets.

@megakorre
Created June 7, 2012 15:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save megakorre/2889294 to your computer and use it in GitHub Desktop.
aggr a macro for reduce comprihension*
(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