Created
March 25, 2011 11:53
-
-
Save hozumi/886748 to your computer and use it in GitHub Desktop.
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
(defmacro _-> | |
([x] x) | |
([x form] (if (seq? form) | |
(if (seq-utils/includes? form '_) | |
(with-meta `(~@(replace {'_ x} form)) (meta form)) | |
(with-meta `(~(first form) ~x ~@(next form)) (meta form))) | |
(list form x))) | |
([x form & more] `(_-> (_-> ~x ~form) ~@more))) | |
;-> and _-> are almost the same behavior until _ is specified. | |
(_-> {} (assoc :a 1) seq) | |
;=> ([:a 1]) | |
; Insert expr in arbitrary place by marking _. | |
(_-> "abcdef" (map int _) (apply hash-map _) (assoc _ 99 :d)) | |
;=> {97 98, 99 :d, 101 102} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment