Created
April 3, 2019 09:03
-
-
Save djtango/2b69221d242ed6a112e47ae72cb1eb67 to your computer and use it in GitHub Desktop.
Clean up all vars in namespace for Clojure
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
(ns user.repl) | |
(defn all-ns-fns | |
"Returns a map of the public intern mappings for the namespace." | |
[ns] | |
(let [ns (the-ns ns)] | |
(->> (ns-map ns) | |
(filter (comp (fn [^clojure.lang.Var v] (and (instance? clojure.lang.Var v) | |
(= ns (.ns v)))) | |
val)) | |
(into {})))) | |
(defn clear-current-ns! [] | |
(->> *ns* | |
all-ns-fns | |
(map (fn [[f-sym f-var]] | |
(ns-unmap *ns* f-sym))))) | |
(defn clean-slate! | |
"This needs to live somewhere else or it'll clean itself up" | |
[] | |
(clear-current-ns!) | |
(require (.getName *ns*) :reload)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment