6

当我尝试在 Clojure 中运行以下代码(来自 REPL)时:

(dotimes [i 5]
  (.start
   (Thread.
    (fn []
      (Thread/sleep (rand 1000))
      (println (format "Finished %d on %s" i (Thread/currentThread)))))))

我收到以下错误:

java.lang.Exception: Unable to resolve symbol: i in this context
clojure.lang.Compiler$CompilerException: NO_SOURCE_FILE:6: Unable to resolve symbol: i in this context
        at clojure.lang.Compiler.analyze(Compiler.java:3713)

我在这里做错了什么?

4

2 回答 2

5

您的代码使用最新的 SVN (1144) 对我有用。

user> (dotimes [i 5] (.start (Thread. (fn [] (Thread/sleep (rand 1000)) (println (format "Finished %d on %s" i (Thread/currentThread)))))))

Finished 0 on Thread[Thread-16,5,main]
Finished 4 on Thread[Thread-20,5,main]
Finished 3 on Thread[Thread-19,5,main]
Finished 1 on Thread[Thread-17,5,main]
Finished 2 on Thread[Thread-18,5,main]

您使用的是 9 月 16 日发布的版本吗?您几乎必须使用 SVN 版本的 Clojure。变化太快了

于 2008-12-04T23:35:31.253 回答
2

我认为您的意思是“从 Clojure 调用 Java”。他们仍在摆弄语法

于 2008-12-05T00:03:12.713 回答