2013-03-04 1 views
5

I는 this 가이드로부터이 코드를 시도 : 출력은 Eclipse에서 실 사용시 REPL 대신 콘솔로 전송되고/반

(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")) 

그것을 실행

는, 출력의 일부가 REPL에 표시하고, 다른 부분은 콘솔에 나타납니다 (사용하지 않기 때문에 보통 숨겨져 있기 때문에 팝업됩니다).

모든 출력을 REPL 창에 보내려면 어떻게해야합니까?

답변

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