I am writing a text game in Clojure. I want the player to type lines on the console, and the game will respond in turn.
Research showed me that (read-line)this is the way I need to get text strings from standard input in Clojure, but it does not work for me.
I am in a new Leiningen project, and I have added a sentence :mainto project.cljindicating a single source file:
(ns textgame.core)
(defn -main [& args]
(println "Entering -main")
; (flush) ;makes no difference if flush are commented out
(let [input (read-line)]
(println "ECHO:" input))
; (flush)
(println "Exiting -main"))
using lein rungives:
Entering -main
ECHO: nil
Exiting -main
In other words, there is no way to enter text on the console (read-line)for reading.
How do I get Clojure to wait for input of characters and a new line and return the corresponding line?
( GNOME Terminal 2.32.1 Linux Mint 11, Leiningen 1.6.1.1 Java 1.6.0_26 Java HotSpot (TM) 64- VM, Clojure 1.2.1.)
: lein repl, (println (read-line)), , -main lein run.