Clojure CLR with multiple namespaces

414 Views Asked by At

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)

1

There are 1 best solutions below

2
On

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?