Created
May 17, 2019 20:00
-
-
Save camsaul/da4953d06a0c472ba26cb79572f2e2e0 to your computer and use it in GitHub Desktop.
Clojure macro to log bindings
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
(defmacro logged-binding {:style/indent 1} [[symb val] & body] | |
`(do | |
(let [val# ~val] | |
(println | |
(colorize.core/magenta | |
(format ~(format "[%s:%d] BOUND %s -> %%s" (ns-name *ns*) (:line (meta &form)) (str symb)) val#))) | |
(let [result# (binding [~symb val#] | |
~@body)] | |
(println | |
(colorize.core/red | |
(format ~(format "[%s:%d] RESTORED %s -> %%s" (ns-name *ns*) (:line (meta &form)) (str symb)) ~symb))) | |
result#)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replace calls to
binding
withlogged-binding