Skip to content

Instantly share code, notes, and snippets.

@fogus
Forked from alandipert/cps.clj
Created July 28, 2012 13:05
Show Gist options
  • Save fogus/3193281 to your computer and use it in GitHub Desktop.
Save fogus/3193281 to your computer and use it in GitHub Desktop.
continuation passing transform macro
(defn & [f k]
(fn [& args]
(k (apply f args))))
(defmacro cps [steps]
(if (seq steps)
`(& ~(first steps)
(cps ~(rest steps)))
`identity))
(defmacro &-> [init & steps]
(list `(cps ~(cons `(constantly ~init) steps))))
(&-> 1 #(* 2 %) inc) ;=> 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment