How are clojure namespaces looked up?
Asked Answered
A

1

10

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?

Acicula answered 23/11, 2011 at 3:51 Comment(1)
After I wrote this question I also found this helpful question: #2223690Acicula
S
14

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://mcmap.net/q/476045/-why-does-clojure-convert-dashes-in-names-to-underscores-in-the-filesystem/32174

Sylph answered 23/11, 2011 at 4:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.