calling clojure-clr from c# namespace confusion

94 views
Skip to first unread message

Liang

unread,
Sep 14, 2013, 5:09:55 AM9/14/13
to vsclojure...@googlegroups.com
Hi group,

I created a clojure-clr console and c# console project within the same solution, and managed to call clojure-clr static function from within c#. And it worked (barely, but worked).

However, one of the confusion I got is, from the c# file, even though I turned off all namespace using statements, the clojure-clr function still can be found. I thought clojure has its own namespace, and expected to include using that namespace before I could refer to its function.

But that's not the case. Clojure namespace is more like a class name rather than namespace in c#. So which c# namespace the clojure function residing in? I wonder if clojure on JVM would have the same issue.

c# code:
System.Console.WriteLine("p.hi => {0}", program.hi());

clojure-clr code:
(ns program
  (:gen-class
   :methods [ #^{:static true} [hi [] String]]))

(defn -hi []
"Hi from ClojureCLR!")

Devin Garner

unread,
Sep 14, 2013, 11:33:14 AM9/14/13
to vsclojure...@googlegroups.com
Liang,

You may want to switch to the google plus group at http://gplus.to/clojureclr, it has more active users.

When you say "barely, but worked", what does that mean?

You're correct, when clojure compiles into a .dll, it does not have a namespace, so a using statement is not required. I would consider this a bug in the clojure.compile.exe, however, it doesn't really cause any problems. I'm not sure how the JVM version of clojure behaves.

If you compile a c# class in a file without namespace _____ { }, it's still legal code & will compile.

If you open up the compiled clojure .dll in jetbrains DotPeek, you can see the decompiled contents of the dll.

The source code for clojureCLR is at github.com/clojure/clojure-clr. David Miller is the project owner. If you would like the bug to be fixed, I would talk to him. If you want to contribute, it shouldn't be too hard to find the issue in the clojure.compile project & submit a code patch to him.

Let me know if you need any more help.

Devin
Reply all
Reply to author
Forward
0 new messages