Skip to content

Instantly share code, notes, and snippets.

@djtango
Created April 3, 2019 09:03
Show Gist options
  • Save djtango/2b69221d242ed6a112e47ae72cb1eb67 to your computer and use it in GitHub Desktop.
Save djtango/2b69221d242ed6a112e47ae72cb1eb67 to your computer and use it in GitHub Desktop.
Clean up all vars in namespace for Clojure
(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