开发者

How can I undefine a function in Clojure?

O开发者_JS百科ften I need to undefine a function in clojure. If I define something with defn how can I undefine it?


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.


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) 


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜