Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureCLR by
    static void Main()
    {
        try
        {
            IFn load = clojure.clr.api.Clojure.var("clojure.core", "load");

            // Below code line seems to expect clojure code (non-compiled) in path
            // bin\Debug\net7.0\clojure\hello.test.clj
            // 
            // OR a compiled dll: 
            //
            // from folderstructure 
            // ./clojure/hello/test.clj
            // > clojure.compile clojure.hello.test
            // 
            // with content in clj file like:
            //   (ns clojure.hello.test)
            //   (defn output[] "ninja")
            var r = load.invoke("hello.test"); 
            IFn helloFn = clojure.clr.api.Clojure.var("clojure.hello.test", "output");
            var result = helloFn.invoke();
            Console.WriteLine("Calling compiled clj from C#, Got: " + result);
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error: {ex.Message}");
        }
    }
by
My question(s):
Is there a simple example for how to go about calling a clojure function from C# code like above?

Any documentation for how to think in regards to namespaces and folder structure in general when trying to interop to clojure from C#?

My main goal right now is to have fun and finally get something running with the nREPL + CIDER.
I was trying to load (using load.invoke)  clojure.tools.nrepl, but getting confused about where to put dll and how to re-name it?!

// with following code
IFn load = clojure.clr.api.Clojure.var("clojure.core", "load");
var r = load.invoke("tools.nrepl");

I output the RT.cs static FileInfo FindFile(string path, string filename)
probePath property and found out:
... being absolute path to my framework folder (net7.0)

...\net7.0\clojure\tools.nrepl.cljr
...\net7.0\bin\clojure\tools.nrepl.cljr
...\net7.0\clojure\tools.nrepl.cljr
...\net7.0\clojure\tools.nrepl.cljc
...\net7.0\bin\clojure\tools.nrepl.cljc
...\net7.0\clojure\tools.nrepl.cljc
...\net7.0\clojure\tools.nrepl.clj
...\net7.0\bin\clojure\tools.nrepl.clj
...\net7.0\clojure\tools.nrepl.clj
...\net7.0\clojure.tools.nrepl.cljr.dll
...\net7.0\bin\clojure.tools.nrepl.cljr.dll
...\net7.0\clojure.tools.nrepl.cljr.dll
...\net7.0\clojure.tools.nrepl.cljc.dll
...\net7.0\bin\clojure.tools.nrepl.cljc.dll
...\net7.0\clojure.tools.nrepl.cljc.dll
...\net7.0\clojure.tools.nrepl.clj.dll
...\net7.0\bin\clojure.tools.nrepl.clj.dll
...\net7.0\clojure.tools.nrepl.clj.dll
Error: Could not locate clojure/tools.nrepl with extensions .cljr, .cljc, .clj, .cljr.dll, .cljc.dll, or .clj.dll on load path.

None of these matches the nuget supplied clojure.tools.nrepl.dll
Action: rename
clojure.tools.nrepl.dll -> clojure.tools.nrepl.clj.dll

Then dll is picked up, but fails to load
clojure.lang.Compiler.AssemblyInitializationException: 'Cannot find initializer
for clojure.tools.nrepl, Version=0.1.0.0, Culture=neutral,
  PublicKeyToken=null.clojure/tools.nrepl'

Please log in or register to answer this question.

...