Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created July 27, 2012 07:08
Show Gist options
  • Save alandipert/3186587 to your computer and use it in GitHub Desktop.
Save alandipert/3186587 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