Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I undefine a function in Clojure?

Tags:

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

like image 429
yazz.com Avatar asked Apr 06 '11 17:04

yazz.com


People also ask

How do you return a function in Clojure?

Clojure doesn't have an explicit return statement. Instead, Clojure will return the result of the last form evaluated in a function (a form is just a valid piece of code).

What does -> mean in Clojure?

It's a way to write code left to right, instead of inside out, e.g. (reduce (map (map xs bar) foo) baz) becomes (-> xs (map bar) (map foo) (reduce baz))


2 Answers

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.

like image 150
Stuart Dabbs Halloway Avatar answered Oct 06 '22 00:10

Stuart Dabbs Halloway


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)  
like image 29
Alex Ott Avatar answered Oct 05 '22 23:10

Alex Ott