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
(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.
.