Skip to content

Instantly share code, notes, and snippets.

@ckirkendall
Forked from fogus/cps.clj
Created July 28, 2012 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckirkendall/3194565 to your computer and use it in GitHub Desktop.
Save ckirkendall/3194565 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