Search code examples
namespacesclojureinteractiveslime

In clojure, how can I undef a var from a namespace?


In clojure I have lines like this that define default values:

(def *http-port* 8080)

I've now decided to formalize these kinds of values into a configuration unit and I would like to undefine the value *http-port* so that I can find the locations that still refer to this value and change them to use the new value. I'm doing a refactoring in other words by moving the value to a different location.

The way I've been doing this is to quit slime and try to restart the slime session. During maven's compile phase errors like these are picked up and I can find and fix one reference at a time. I then fix the error, wash rinse and repeat. This is obviously frustrating.

How would I do this while connected to a slime session?


Solution

  • If I understand you correctly, ns-unmap should do what you want:

    user=> foo
    java.lang.Exception: Unable to resolve symbol: foo in this context (NO_SOURCE_FILE:1)
    user=> (def foo 1)
    #'user/foo
    user=> foo
    1
    user=> (ns-unmap (find-ns 'user) 'foo)
    nil
    user=> foo
    java.lang.Exception: Unable to resolve symbol: foo in this context (NO_SOURCE_FILE:1)