How do you undef / unintern a symbol in Clojure? (ns-unmap 'namespace 'symbol).
Suppose that you’re working at a REPL and you have namespaces a, b, and c, where c :uses both a and b (meaning that it imports their namespace contents into its own namespace.) You write a function foo in a, but then later you decide to move it to b. Bam, you get a namespace collision exception the next time you reload c.
The symbol foo in c’s namespace is already bound to your code in memory. Simply deleting the source code from a’s source file is not enough.
Of course, you could be brutish and simply kill your Clojure REPL process and restart it, but who wants to go through all that? We need a way to unbind the obsolete symbol in a. The solution is simple: just
(ns-unmap 'a 'foo)
and the symbol is removed from package a’s namespace. (This is called undef or unintern in other Lisp dialects.)
Edit: Since we’ve :used a from c, there will also now be a foo symbol in the c namespace, and we must also (ns-unmap 'c 'foo). Thanks Meikel!
Popularity: 22% [?]
If you like this post and would like to receive updates from this blog, please subscribe our feed.

March 25th, 2010 at 4:59 AM
Note, that you will also have to
ns-unmapthe symbol fromcsince you used:use.March 25th, 2010 at 2:54 PM
Good catch, thanks. I’ll update the post to mention that.