Last active
January 2, 2016 04:59
-
-
Save knjname/8254037 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
| ;;; First version | |
| (defmacro -<> [subject & body] | |
| `(let [~'<> ~subject] | |
| ~(if (empty? body) | |
| '<> | |
| `(-<> ~(first body) | |
| ~@(rest body))))) | |
| (-<> "asdf" | |
| (.length <>) | |
| (* 2 <>) | |
| #(+ 30 <> %) | |
| (<> 100)) | |
| ;; => 138 | |
| ;; To be: | |
| ;; (let* | |
| ;; [<> "asdf"] | |
| ;; (let* | |
| ;; [<> (. <> length)] | |
| ;; (let* | |
| ;; [<> (* 2 <>)] | |
| ;; (let* | |
| ;; [<> #(+ 30 <> %)] | |
| ;; (let* [<> (<> 100)] <>))))) | |
| ;;; Better version. | |
| (defmacro -<> [& body] | |
| `(let | |
| [~@(interleave (repeat '<>) body)] | |
| ~'<>)) | |
| (-<> "asdf" | |
| (.length <>) | |
| (* 2 <>) | |
| #(+ 30 <> %) | |
| (<> 100)) | |
| ;; => 138 | |
| ;; To be: | |
| ;; (let* | |
| ;; [<> | |
| ;; "asdf" | |
| ;; <> | |
| ;; (. <> length) | |
| ;; <> | |
| ;; (* 2 <>) | |
| ;; <> | |
| ;; #(+ 30 <> %) | |
| ;; <> | |
| ;; (<> 100)] | |
| ;; <>) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment