Created
March 11, 2010 04:41
-
-
Save pervognsen/328830 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(ns psykotic.threader | |
(:use clojure.walk)) | |
(defmacro >> [& xs] | |
(reduce (fn [x1 x2] | |
(let [x1- (gensym)] | |
`(let [~x1- ~x1] | |
~(postwalk (fn [x] (if (= x '%) x1- x)) x2)))) | |
(macroexpand-all xs))) | |
(println (>> 42 (+ 8 %) (/ % 2))) ; Vary threading position per expression | |
(println (>> 42 (+ 8 %) (* % %))) ; Refer multiple times to previous result, without reevaluation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment