Skip to content

Instantly share code, notes, and snippets.

@knjname
Last active January 2, 2016 04:59
Show Gist options
  • Select an option

  • Save knjname/8254037 to your computer and use it in GitHub Desktop.

Select an option

Save knjname/8254037 to your computer and use it in GitHub Desktop.
;;; 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