Created
September 21, 2010 20:41
-
-
Save MayDaniel/590490 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
(use 'clojure.walk) | |
(defmacro ->_ | |
"Threads the forms, replacing underscores with the result of the last expression." | |
([x] x) | |
([x form] (if (seq? form) | |
(with-meta (postwalk-replace {'_ x} form) (meta form)) | |
(list form x))) | |
([x form & more] `(->_ (->_ ~x ~form) ~@more))) | |
(comment | |
(macroexpand-all '(->_ 5 (+ 7 _) (* _ 9) (- _ 88))) | |
;; (- (* (+ 7 5) 9) 88) | |
(->_ [1 2 3] last (* _ _)) | |
(->_ 5 (partial + _) (comp inc _ _) (_ 10)) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment