Skip to content

Instantly share code, notes, and snippets.

@camsaul
Created May 17, 2019 20:00
Show Gist options
  • Save camsaul/da4953d06a0c472ba26cb79572f2e2e0 to your computer and use it in GitHub Desktop.
Save camsaul/da4953d06a0c472ba26cb79572f2e2e0 to your computer and use it in GitHub Desktop.
Clojure macro to log bindings
(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#))))
@camsaul
Copy link
Author

camsaul commented May 17, 2019

for debugging purposes

@camsaul
Copy link
Author

camsaul commented May 17, 2019

Replace calls to binding with logged-binding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment