Skip to content

Instantly share code, notes, and snippets.

@Janiczek
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Janiczek/fb6bcea479c049812e66 to your computer and use it in GitHub Desktop.
Save Janiczek/fb6bcea479c049812e66 to your computer and use it in GitHub Desktop.
(ns print-let)
;; https://www.youtube.com/watch?v=3eqW7rghDew
(defn print-form [[id form]]
`(~id ~form _# (println ~(str id ":") ~id)))
(defmacro print-let [bindings & body]
(let [binding-pairs (partition 2 bindings)
bindings-with-prints (apply concat (map print-form binding-pairs))]
`(let [~@bindings-with-prints]
~@body)))
;; usage:
(print-let [x "a"
y (str x "b")
z (str y y)]
z)
(comment ;; =>
(let [x "a"
_ (println "x:" x)
y (str x "b")
_ (println "y:" y)
z (str y y)
_ (println "z:" z)]
z))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment