1

I wrote a small namespace to do some database operations and I would like to use it from within another namespace. Normally having the files in the same directory and then doing

(ns program (:require [other-ns :as other]) (:gen-class))

would be all that's necessary. However this doesn't work in Clojure CLR, compiler complains about not knowing about other-ns. So what is the proper method of doing this? Having a seperate assembly for every namespace?

[EDIT] Another example

another.clj

  (ns another)

  (defn hello [name] (str "Hello " name))

program.clj

  (ns program
    (:require [another :as a])
    (:gen-class))

I load up program.clj in the repl and get this message:

FileNotFoundException Could not locate another.clj.dll or another.clj on load path. clojure.lang.RT.load (d:\work\clojure-clr\Clojure\Clojure\Lib\RT.cs:3068)

Matthew
  • 11,203
  • 9
  • 38
  • 44
  • Take a look at http://clojure.org/libs and check that you've got every namespace/file in the expected place. If you can't figure out what's wrong, please show the (ns ..) forms, their locations in the filesystem and the errors you're seeing. – Joost Diepenmaat Apr 10 '12 at 17:44
  • Do you get the error when you compile the project first? Try building it then loading program.clj in the REPL. The only other thing I can think of asking is are you using the new vsClojure? – Rob Apr 13 '12 at 12:45

1 Answers1

0

I created two files in the same directory filea.clj and fileb.clj. Here's filea.clj:

(ns filea)

(defn hi []
  (println "hi from filea"))

Here's fileb.clj:

(ns fileb
  (require [filea :as a])
  (:gen-class))

(defn -main []
  (println "hi from fileb")
  (a/hi))

I then changed into the directory where these files live and ran:

C:\temp\multi-ns>clojure.compile fileb Compiling fileb to . -- 59 milliseconds.

And when I ran it I saw:

C:\temp\multi-ns>c:\Tools\clojure-clr-1.3.0-Debug-4.0\fileb.exe hi from fileb hi from filea

Are you using vsClojure or writing your code outside of VS?

Rob
  • 166
  • 1
  • 4
  • I was using VsClojure, perhaps a bug there. – Matthew Apr 12 '12 at 17:11
  • Just installed vsClojure and did the same type of thing as I did above except I kept the program.clj file and used it in place of fileb.clj in my example above. I didn't have a problem. Can you post your code or the layout of your project directory and name spaces? – Rob Apr 12 '12 at 17:28