Call Java from Clojure

When I try to run the following code (from REPL) in Clojure:

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

I get the following error:

 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) 

What am I doing wrong here?

+6
java clojure language-interoperability
source share
2 answers

Your code works for me using the latest 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] 

Are you using the September 16 issue? You should almost use the SVN version of Clojure. It changes too fast.

+5
source share

I think you mean "Call Java from Clojure". They were still messing with the syntax .

+2
source share

All Articles