Search code examples
clojureleiningenvimclojure

How do I remove a function from the lein repl?


During a lein REPL session, I may define a number of functions. However, sometimes I would want the session to 'forget' them - for example when I execute (run-all-tests), this highlights failures from tests that I no longer need. Is there a way to remove functions from the session, or to clean it, without restarting?


Solution

  • use ns-unmap as described on the Clojure namespaces page http://clojure.org/namespacesuser>

    (defn foo [x] (inc x))                    
    #'user/foo     
    user> (foo 3)       
    4                                                                                
    user> (ns-unmap *ns* 'foo)     
    nil
    user> (foo 3)
    CompilerException java.lang.RuntimeException: Unable to resolve symbol: foo in this context, compiling:(NO_SOURCE_PATH:1:1)