2

我正在尝试在 CLR 上运行 Clojure,但遇到了一些基本问题。基于这个问题,我正在使用以下代码:

在 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))))

然后在 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();
        }
    }
}

当我运行 Program.cs 时,它会引发 TypeInitializationError 错误消息“无法在加载路径上找到 clojure/core.clj.dll 或 clojure/core.clj”。为了调试,我添加了以下行:

System.Environment.SetEnvironmentVariable("clojure.load.path", "c:\clojure");
System.Console.WriteLine(System.Environment.GetEnvironmentVariable("clojure.load.path"));
System.Console.WriteLine(RT.CLOJURE_LOAD_PATH);

正如我所料,第一个 WriteLine 显示“c:\clojure”。第二个显示“clojure.load.path”。我的理解是运行时查看加载路径的环境变量。那么为什么找不到呢?如何设置加载路径?

4

2 回答 2

2

担,

您需要在项目中包含以下与 clojureclr 相关的 dll:

`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`

一旦你有了这些你将包含的程序集,你就可以运行棒球.exe。如果你还没有,我可以查看这篇博文:http ://www.myclojureadventure.com/2011/12/intro-to-clojure-clr-calling-clojure.html 我遇到了同样的问题在那之前有什么刺激了这个职位。

于 2012-01-05T21:07:41.813 回答
0

我对 Clojure/CLR 了解不多,但我不会假设在加载 Clojure 运行时更改环境变量会改变 Clojure 加载路径。它在 Clojure/JVM 中绝对不会那样工作——这些环境变量 -> 系统设置显然是为了在加载主代码后修复。在 Clojure/JVM 中,这通常意味着您从另一个已经为您设置了加载路径的主 clojure 进程(通常是直接启动 JVM 的批处理脚本或 leiningen/cake 调用)启动主 clojure 进程。

于 2012-01-05T20:21:08.793 回答