Clojure namespace

I created a 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 test_fu from my namespace?

I 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
+3
source share
2 answers

There are two problems that I see. First, Clojure expects ns names to use the character - where file names will use the _ character (you cannot use - in ns or _ names in file names); so you need to use

(ns shell-space)

at the top of the file.

Secondly, your script launcher does not use the $ CLASSPATH environment variable, instead it uses $ CLOJURE_CLASSPATH. Emphasize that according to your preferences and everything should be fine.

: .clj , . . ~/dev/projects/ , , ( "shell-space" ). ~/dev/projects/diary/shell, (require 'shell.shell-space).

+4

shell_space.clj CLOJURE_HOME, .

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

Source: https://habr.com/ru/post/1725838/


All Articles