tags:

views:

136

answers:

2

I have created sample namespace:

[demas @arch.local.net ][~/dev/projects/diary]% cat shell_space.clj 
(ns shell_space)

(defn test_fu []
   (println "test-shell"))

How can I use the test_fu from my namespace?

I have tried:

[demas @arch.local.net ][~]% clj
Clojure 1.1.0-alpha-SNAPSHOT
user=> (require 'shell_space)
java.io.FileNotFoundException: Could not locate shell_space__init.class or shell_space.clj on classpath:  (NO_SOURCE_FILE:0)
user=> (require '/home/demas/dev/projects/diary/shell_space)
java.lang.Exception: Invalid token: /home/demas/dev/projects/diary/shell_space java.lang.Exception: Unmatched delimiter: )

This is my CLASSPATH:

[demas @arch.local.net ][~]% echo $CLASSPATH
/home/demas/dev/projects/diary
A: 

I move shell_space.clj to CLOJURE_HOME and it helps me.

 [demas @arch.local.net ][~]% cat /etc/profile.d/clojure.sh 
 export CLOJURE_HOME=/usr/share/clojure
demas
+2  A: 

There are two issues that I can see. Firstly, Clojure expects ns names to use the - character where filenames use the _ character (you can't really use - in ns names or _ in filenames); so, you need to use

(ns shell-space)

at the top of your file.

Secondly, your launcher script makes no use of the $CLASSPATH environment variable, it uses $CLOJURE_CLASSPATH instead. Tweak that to your preference and all should be well.

For the sake of completeness: you need to put that .clj file in a directory which lies below one of the directories on your classpath in the filesystem hierarchy. E.g. if you put ~/dev/projects/diary on your classpath and the file is right there, you should be able to (require 'shell-space). If the file is in ~/dev/projects/diary/shell, you should be able to (require 'shell.shell-space).

Michał Marczyk