Skip to content

Instantly share code, notes, and snippets.

@RutledgePaulV
Created October 29, 2018 13:13
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 RutledgePaulV/8b7513bf9ea0b37d9c519e29dc814327 to your computer and use it in GitHub Desktop.
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.
(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