claj
claj

Reputation: 5402

Destroy variable in clojure

When using the repl, sometimes you want to destroy a variable because it somehow get in the way of your programming (most usually namespace collisions).

Is there a way to destroy a variable in clojure?

user>(def x 1)
#'user/x
user>(aggressive-destroy! x)
nil
user>x
Unable to resolve symbol: x in this context

Upvotes: 11

Views: 827

Answers (1)

Scott
Scott

Reputation: 17257

ns-unmap

user=> (def my-var "this is my-var!")
#'user/my-var
user=> (println my-var)
this is my-var!
nil
user=> (ns-unmap 'user 'my-var)
nil
user=> (println my-var)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: my-var in this context, compiling:(NO_SOURCE_PATH:13) 
user=> 

Upvotes: 18

Related Questions