I have a src/example/foo.clj
file:
(ns example.foo)
(defn my-fn []
(println "Hello, world!"))
I can open it in Emacs and spin up a REPL using C-c M-j
and play with it. I don't want to type long namespace names, so I alias the ones I need:
user> (require '[example.foo :as foo])
; => nil
So far so good. Everything works fine at this point.
user> (foo/my-fn)
; Hello, world!
; => nil
If I try to use a function that doesn't exist, I get a CompilerException
as expected:
user> (foo/my-function)
; CompilerException java.lang.RuntimeException: No such var: foo/my-function
Now, since obviously foo
still needs a lot of work, I'm actively making changes to it. I decide to rename one of my functions to something more descriptive.
src/example/foo.clj
:
(ns example.foo)
(defn greet-world []
(println "Hello, world!"))
I then save the file and reload it using C-c C-x
, and that's where everything seems to break. If I try to call the function using its old name, I get an IllegalStateException
instead of a CompilerException
:
user> (foo/my-fn)
; IllegalStateException Attempting to call unbound fn: #'example.foo/my-fn
And if I use its new name:
user> (foo/greet-world)
; CompilerException java.lang.RuntimeException: No such var: foo/greet-world
So now my alias namespace is completely useless. I can, however, call the function using its full name:
user> (example.foo/greet-world)
; Hello, world!
; => nil
But of course, if I try to run require
again, I get an error:
user> (require '[example.foo :as foo])
; IllegalStateException Alias foo already exists in namespace user, aliasing example.foo
So, how can I actually reload a namespace without restarting my entire REPL?