How can I undefine a function in Clojure?

前端 未结 3 1049
你的背包
你的背包 2021-01-07 17:56

Often I need to undefine a function in clojure. If I define something with defn how can I undefine it?

相关标签:
3条回答
  • 2021-01-07 18:06

    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) 
    
    0 讨论(0)
  • 2021-01-07 18:12

    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 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题