clojure lein (read-line) stdin woes

2019-06-17 10:55发布

So regular clojure repl works fine, (read-line) collects input, then echos it. Using lein repl though, never echoes any input characters, nor does it ever allows me to return from any stdin reading commands.

I'm sure it has something to do with rebinding in, but was wondering if there is a workaround/fix?

Thanks.

3条回答
Animai°情兽
2楼-- · 2019-06-17 11:10

This works for me now: Wrap your read-line calls with the macro with-read-line-support which is in ns swank.core [since swank-clojure 1.4+ I believe]:

(use 'swank.core)
(with-read-line-support 
  (println "a line from Emacs:" (read-line)))

Thanks to Tavis Judd for the fix.

查看更多
等我变得足够好
3楼-- · 2019-06-17 11:21

This is due to a bug in ant; it prevents the stdin stream from the subprocess it launches from being used. But the telnet trick should work since lein repl launches a socket repl server; it works fine here.

一夜七次
4楼-- · 2019-06-17 11:27

Connect to the REPL via telnet.

$ lein repl
REPL started; server listening on localhost:63849.
user=> 
[1]+  Stopped                 lein repl
$ telnet localhost 63849
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
user=> (read-line)
hello
"hello"
user=>
查看更多
登录 后发表回答