Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are clojure namespaces looked up?

To start off I am not a Java programmer, so it would be helpful if your answers are not defined in terms of Java (inasmuch as that makes sense).

I have a leiningen project (specifically a web project using noir) using what seems to be a common pattern of putting your clojure source files in src/YOUR-NAMESPACE/. So far I've had success adding directories and files, and I have been using the file path as the basis for the ns (following the pattern I see in the generated code).

I added a new file that did not work, and I'm wondering why. It's path is PROJECT-ROOT/src/bayou/lib/api-helpers.clj and its namespace is (ns bayou.lib.api-helpers). The specific error I'm getting is:

java.io.FileNotFoundException: Could not locate bayou/lib/api_helpers__init.class or bayou/lib/api_helpers.clj on classpath

What are all the steps one as to take in order for clojure to recognize a namespace?

like image 679
benekastah Avatar asked Nov 23 '11 03:11

benekastah


1 Answers

The problem is the hyphen in the namespace.

From the Joy of Clojure

HYPHENS/UNDERSCORES If you decide to name your namespaces with hyphens, à la my-cool-lib, then the corresponding source file must be named with underscores in place of the hyphens (my_cool_lib.clj).

Here is the underlying explanation: https://stackoverflow.com/q/4451693/32174

like image 69
Julien Chastang Avatar answered Nov 01 '22 06:11

Julien Chastang