Reputation: 1464
I'm trying to run Clojure on the CLR and getting stuck on some basic issues. Based on this question I am using the following code:
In program.clj:
(ns program
(:require [clojure.core])
(:gen-class
:methods [#^{:static true} [output [int int] int]]))
(defn output [a b]
(+ a b))
(defn -output [a b]
(output a b))
(defn -main []
(println (str "(+ 5 10): " (output 5 10))))
Then in Program.cs:
using System;
using clojure.lang;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
program p = new program();
System.Console.WriteLine(p.output(5, 9));
System.Console.ReadLine();
}
}
}
When I run Program.cs, it throws a TypeInitializationError with the error message "Could not locate clojure/core.clj.dll or clojure/core.clj on load path." To debug, I added the lines:
System.Environment.SetEnvironmentVariable("clojure.load.path", "c:\clojure");
System.Console.WriteLine(System.Environment.GetEnvironmentVariable("clojure.load.path"));
System.Console.WriteLine(RT.CLOJURE_LOAD_PATH);
The first WriteLine shows "c:\clojure", as I would expect. The second one shows "clojure.load.path". My understanding was that the runtime looked to the environment variables for the load path. So why is it not finding it? How else does one set the load path?
Upvotes: 2
Views: 529
Reputation: 166
Dan,
You'll need to include the following clojureclr related dlls to your project:
`Clojure.dll,
clojure.clr.io.clj.dll,
clojure.core.clj.dll,
clojure.core.protocols.clj.dll,
clojure.core_clr.clj.dll,
clojure.core_deftype.clj.dll,
clojure.core_print.clj.dll,
clojure.core_proxy.clj.dll,
clojure.genclass.clj.dll,
clojure.gvec.clj.dll`
Once you have those you'll assemblies included you'll be able to run baseball.exe. If you haven't already I you can check out this blog post: http://www.myclojureadventure.com/2011/12/intro-to-clojure-clr-calling-clojure.html I ran into the same problem you are having before that is what spurred the post.
Upvotes: 2
Reputation: 17773
I don't know much about Clojure/CLR, but I would not assume that changing the environment variables after loading the Clojure runtime would change the Clojure load paths. It definitely doesn't work like that in Clojure/JVM - these kinds of environment var -> system settings apparently are intended to be fixed once the main code has loaded. In Clojure/JVM, that generally means you launch the main clojure process from another one that has already set the load path for you (typically, a batch script that launches the JVM directly or a leiningen/cake invocation).
Upvotes: 0