Why can't I print from background threads in Clojure Cider REPL in emacs?

前端 未结 4 912
执笔经年
执笔经年 2020-12-03 04:10

If I try to evaluate the following code in my emacs cider-repl, nil is returned, as expected, but none of the printing takes place in the repl buffer or console. How can I m

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 04:32

    The behavior of println is to use a dynamically bound var called *out* as its output stream. emacs dynamically binds *out* to go to the repl buffer for code evaluated in the repl buffer, but if you create a thread, that thread's *out* gets the root binding of *out*, which in the case of cider will not be the repl buffer.

    If you started the repl using cider-jack-in, when you look at you buffer list there should be a buffer with a name like *nrepl-server* which contains the output of the root *out* binding. Here is the contents of mine after running your code:

    nREPL server started on port 52034 on host 127.0.0.1 - nrepl://127.0.0.1:52034
    Finished 1 on Thread[Thread-9,5,main]
    Finished 0 on Thread[Thread-8,5,main]
    Finished 2 on Thread[Thread-10,5,main]
    Finished 3 on Thread[Thread-11,5,main]
    Finished 4 on Thread[Thread-12,5,main]
    

    If you did not use cider-jack-in, the output will print to the terminal where you started the nrepl process.

提交回复
热议问题