0
votes

I'm a bit of a Clojure newbie and something in the REPL is really confusing me.

I have a project called "misc" and a namespace at "misc/src/counter_window.clj". When I do enter the REPL from the project root folder I want to import counter_window's functions, but I seem to have to go through the following weird tango every time:

user=> (use 'counter-window)
FileNotFoundException Could not locate counter_window__init.class or counter_window.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.  clojure.lang.RT.load (RT.java:449)

user=> (use 'misc.counter-window)

CompilerException java.lang.Exception: namespace 'misc.counter-window' not found after loading '/misc/counter_window', compiling:(/tmp/form-init2530455467319465680.clj:1:1) 
user=> (use 'counter-window)
nil ;; the import succeeds this third time.

The warning in the FileNotFound exception doesn't seem to apply because the namespace is called counter-window in the counter_window.clj file already.

So why does this happen? Why does the import not work the first time, but then succeed the third time?

1

1 Answers

1
votes

I think there is a direct relation between file path and the namespace. A file src/counter_window.clj ought to have the namespace declaration (ns counter-window).

A namespace misc.counter-window should be defined in the file src/misc/counter_window.clj. ie it will have the form (ns misc.counter-window). Note that misc is a folder inside src. Your project could be named anything, I don't think it would affect the namespaces.

Assuming what you wanted was the namespace misc.counter-window and your file is correspondingly at src/misc/counter_window.clj, the following works in the repl

(use '[misc.counter-window])