Clojure (read-line) returns nil; doesn't prompt

I am working on my first own 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-H][1-8]\s[A-H][1-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))))))

Pay attention to the place where read-linecommented out and replaced by terminal-input. read-linegave 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 have never had the opportunity to enter something as input. If it were Java, I would start playing small games with a garbage collector (for example, when called Scanner.next()), but with Clojure I did not know what to do except placing there (flush).

For what it's worth, it's using SLIME.


terminal-input , , -, loop/recur. , read-line.

.

+5
3

swank- clojure 1.4.0-SNAPSHOT, read-line swank.core/with-read-line-support,

(with-read-line-support (println "a line from Emacs:" (read-line))

https://github.com/technomancy/swank-clojure/commit/f4a1eebc4d34f2ff473c4e5350f889ec356f5168

+8

read-line SLIME. , .

+9

, :

(swank.core/with-read-line-support
   (read-line))
0

All Articles