Created
July 27, 2012 07:08
-
-
Save alandipert/3186587 to your computer and use it in GitHub Desktop.
continuation passing transform macro
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 & [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