Created
October 29, 2018 13:13
-
-
Save RutledgePaulV/8b7513bf9ea0b37d9c519e29dc814327 to your computer and use it in GitHub Desktop.
Few functions are dynamic vars. Make them dynamic after the fact by adding a second implementation that only runs for specific threads.
This file contains 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
(defonce ^:dynamic *hooked* false) | |
(defn hook [var f] | |
(alter-var-root var | |
(fn [original] | |
(fn [& args] | |
(if *hooked* | |
(apply f args) | |
(apply original args)))))) | |
(defmacro with-hooks [& body] | |
`(binding [*hooked* true] ~@body)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment