Import other .clj files

986 views
Skip to first unread message

MohanR

unread,
May 12, 2011, 2:28:22 AM5/12/11
to Clojure
Hi,

I am trying to import .clj files. What is the variable( load-
path/swank-clojure-classpath) that should point to the directory
containing other .clj files with their own namespaces ? I use
ClojureBox.

I am loading the file using C-c C-l but I see this error

Could not locate messagebus/mycyclicbarrier__init.class or messagebus/
mycyclicbarrier.clj on classpath

I understand how Java classpath's work but not this.

Thanks,
Mohan

MohanR

unread,
May 13, 2011, 1:53:16 AM5/13/11
to Clojure
I am able to set the swank-clojure-classpath and also verify it using
C-h v. It has the current directory "." and also other directories
where .clj files are located

If a .clj file has a namespace I ensure the classpath points to the
root of the namespace folder structure like I do with Java.


What else is missing ?

MohanR

unread,
May 13, 2011, 3:15:22 AM5/13/11
to Clojure
It is solved but the rules are not clear.

If I have (ns test) in both .clj files and the files are in /test then
I am able to call one from the other. I am not specifically pointing
my classpath to /test at all.

What is the link between classpath, ns and the folder structure ?

Thanks,
Mohan


Jonathan Fischer Friberg

unread,
May 13, 2011, 6:55:00 AM5/13/11
to clo...@googlegroups.com
With the structure:

test
- test1.clj
- test2.clj

then test1.clj should start with (ns test.test1) and test2.clj should start with (ns test.test2)

Jonathan



--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

MohanR

unread,
May 16, 2011, 1:02:31 AM5/16/11
to Clojure
As mentioned in my previous question I didn't use (ns test.test1) but
only (ns test) and it worked.


(ns test.test1) throws

java.lang.Exception: Unable to resolve symbol

when I call a method in the other .clj file


Thanks,
Mohan

Jonathan Fischer Friberg

unread,
May 16, 2011, 10:17:00 AM5/16/11
to clo...@googlegroups.com
Putting (ns test) in both files means that the content of the files are in the same namespace, this is essentially the same as putting everything in the same file. To be able to access something from the other file you need to "require", or "use" the other namespace.

If you want to access the content of test1 in test2, you can put the following in the files:

test1.clj
(ns test.test1)

test2.clj
(ns test.test2 (:use test.test2))
; everything in test1 is accessible

For more detail:
http://clojure.org/namespaces
http://blog.8thlight.com/articles/2010/12/6/clojure-libs-and-namespaces-require-use-import-and-ns

Jonathan



Thanks,
Mohan

Reply all
Reply to author
Forward
0 new messages