Clojure's (read-line) returns nil; does not prompt?

This will work now with swank-clojure 1.4.0-SNAPSHOT if you wrap the call to read-line in swank. Core/with-read-line-support like this.

Up vote 5 down vote favorite share g+ share fb share tw.

I'm working on my first proper Clojure program--a chess game. I have the following: (defn human-move board (board-utils/print-board board) (print "Enter your move, like this: 'E7 E5' ...") (loop raw-move (terminal-input) ;;(read-line) (println "I just received" raw-move) (if (re-matches #"A-H1-8\sA-H1-8" raw-move) (parse-move raw-move) (do (println "Invalid format! There should be a letter, number, space, letter, and final number.

") (print "Try again: ") (recur (read-line)))))) Note the place where read-line is commented out and replaced by terminal-input. Read-line was giving me a NullPointerException, so for diagnostic purposes: (defn terminal-input (println "input") (let whatnot (read-line) (println "received" whatnot) whatnot)) Then, when I call human-move. ... +---+---+---+---+---+---+---+---+ | P | P | P | P | P | P | P | P | +---+---+---+---+---+---+---+---+ | R | N | B | Q | K | B | N | R | +---+---+---+---+---+---+---+---+ Enter your move, like this: 'E7 E5' ...input received nil I just received nil I never got a chance to type something in as input.

Were this Java, I'd start playing little games with the garbage collector (calling Scanner.next(), for instance), but with Clojure I didn't know what to do besides putting the (flush) in there. For what it's worth, this is with SLIME. I also tried to have terminal-input provide dummy data, and learned that I'm apparently using loop/recur incorrectly.

I haven't investigated it super-thoroughly though, since I've been distracted by the read-line issues. Thanks in advance. Clojure link|improve this question edited May 2 '11 at 22:44 asked May 2 '11 at 19:13Tim Macdonald35317 100% accept rate.

This will work now with swank-clojure 1.4.0-SNAPSHOT if you wrap the call to read-line in swank. Core/with-read-line-support like this (with-read-line-support (println "a line from Emacs:" (read-line)) github.com/technomancy/swank-clojure/com....

Btw, I've also added read-from-minibuffer and y-or-n-p support. – Tavis Rudd Jan 11 at 17:32 That's pretty awesome. I look forward to having a reason to try this.

– amalloy Jan 11 at 18:41.

Read-line doesn't work in SLIME. I can't find the discussion thread about this, but it's true.

1 for "but it's true". – ponzao May 2 '11 at 20:25 Thud. Um...is there some kind of workaround?

Would it be worth playing games with Java's Scanner class? – Tim Macdonald May 2 '11 at 22:11 Have a look at stackoverflow.com/questions/3790889/… - a bit old, but probably still helpful. – amalloy May 2 '11 at 23:37 They say: "But I just pushed a bugfix to lein repl, and now read-line works in the repl for me.

Let me know if it works for you in the latest 1.4.0-SNAPSHOT" So in project. Clj, I changed :dev-dependencies swank-clojure "1.2.1" to ...swank-clojure "1.4.0-SNAPSHOT. Then I ran lein deps && lein swank, reconnected with Emacs, and still have the problem.

For what it's worth: $ lein version Leiningen 1.5.2 on Java 1.6.0_24 Java HotSpot(TM) 64-Bit Server VM I'm not really sure what to do with the telnet business they mentioned. I guess I should talk to the lein mailing list? – Tim Macdonald May 3 '11 at 13:10 That thread is about a sort-of unrelated issued with reading from stdin with lein repl.

AFAIC, reading from an input stream connected to the Slime repl is simply not implemented swank-clojure. – raek May 3 '11 at 14:19.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions