在Eclipse/CounterClockWise中使用线程时,输出将发送到控制台而不是REPL

Cho*_*per 5 eclipse clojure counterclockwise

我尝试了指南中的代码:

(defn my-fn [ms]
  (println "entered my-fn")
  (Thread/sleep ms)
  (println "leaving my-fn"))

(let [thread (Thread. #(my-fn 1))]
  (.start thread)
  (println "started thread")
  (while (.isAlive thread)
    (print ".")
    (flush))
  (println "thread stopped"))
Run Code Online (Sandbox Code Playgroud)

当我执行它时,部分输出显示在REPL中,而另一部分显示在控制台中(由于我通常将其隐藏起来因为我不使用它而弹出).

我想将所有输出发送到REPL窗口,我该如何实现?

mob*_*yte 6

这是因为*out*在新线程中没有绑定到REPL编写器.您可以手动绑定它:

(let [thread (let [out *out*] 
               (Thread. #(binding [*out* out] 
                           (my-fn 1))))]
  (.start thread)
  (println "started thread")
  (while (.isAlive thread)
    (print ".")
    (flush))
  (println "thread stopped"))
Run Code Online (Sandbox Code Playgroud)