Paul Reiners
Paul Reiners

Reputation: 7894

Can't load-file

I have the file male_female.clj in the following directory on Windows:

C:\Documents and Settings\vreinpa\My Documents\Books\ProgrammingClojure\code\src\examples

Before starting the REPL, I switch to that directory:

U:\>c:
C:\>cd C:\Documents and Settings\vreinpa\My Documents\Books\ProgrammingClojure\code\src\examples

I then start the REPL:

C:\Documents and Settings\vreinpa\My Documents\Books\ProgrammingClojure\code\src\examples>lein repl
Warning: classpath not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic classpath or change the name.
REPL started; server listening on localhost:13278.

I then try to load the file, but get the following error:

user=> (load-file "male_female.clj")
user=> FileNotFoundException male_female.clj (The system cannot find the file specified)   java.io.FileInputStream.open (:-2)

What am I doing wrong here? The file is definitely in the directory that I changed to before starting the REPL.

Upvotes: 1

Views: 2145

Answers (1)

okonomichiyaki
okonomichiyaki

Reputation: 8485

Are you working with the Programming Clojure repo? I just cloned it and tried the same thing (albeit on a Mac) and had the same error.

If you are, try running lein repl from the root of the Git repo and then use (load "examples/male_female"). You can then access the definitions in this file by switching to the namespace with (in-ns 'examples.male-female) or fully with the fully qualified name: examples.male-female/m, etc. This worked for for me.

I'm not sure where load-file looks, but I think load will look in the Java classpath. You can inspect the classpath from a Clojure REPL with (System/getProperty "java.class.path").

edit

I experimented with it after reading the docs on load-file and found that this worked too: (load-file "src/examples/male_female.clj"), regardless of where I was in the project. This might be something to do with Leiningen and what it considers the project root.

Upvotes: 3

Related Questions