Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Destroy variable in clojure

Tags:

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
like image 562
claj Avatar asked Jan 12 '12 21:01

claj


1 Answers

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=> 
like image 108
Scott Avatar answered Oct 03 '22 10:10

Scott