Often I need to undefine a function in clojure. If I define something with defn how can I undefine it?
Asked
Active
Viewed 3,800 times
3 Answers
40
There is no one-argument version, because the same Var can be mapped in more than one namespace. If you are working from the REPL, you often want to unbind from the user namespace, e.g.
(ns-unmap 'user 'symbol-to-unbind)
The first argument to ns-unmap can be a symbol or a namespace, and the second argument should be a symbol.

Stuart Dabbs Halloway
- 1,658
- 12
- 10
-
3Any reason why ns-unmap can't just take a single qualified symbol, e.g. `'user/symbol-to-unbind`? – mikera Feb 13 '12 at 10:13
21
I think, that you can use ns-unmap to do this.
P.S. Couldn't add this code into comment, so i put it here. To unmap function in current namespace, you need to use following code:
(ns-unmap *ns* 'method)

Alex Ott
- 80,552
- 8
- 87
- 132
-
I get java.lang.IllegalArgumentException when I use (ns-unmap ::some-method). Is there a one argument version? – yazz.com Apr 06 '11 at 18:07
7
If you have:
(def x 42)
It might be useful to unbind the var:
(.unbindRoot #'x)
Now, if you try this
x
You get:
#<Unbound Unbound: #'user/x>

David J.
- 31,569
- 22
- 122
- 174