简体   繁体   中英

How to make Clojure command line

I am new to Clojure, I wish to create a command line in clojure.

I am using lein, The app is simply waiting for user to type something and when press enter, it will print the line.

I cannot seems to make Clojure wait forever with lein run Is there any other way?

Here is my code.

(defn -main [& args] 
   (read-line)
)

so when I type something and press enter, the whole code stops, I want to take the input of user typing and process it continuously. I mean each time user press enter, he/she should be able to continue to next line and program will run forever.

You need to loop for the user inputs then and provide some means to break the loop (yet, ctrl-c also works). Eg

(loop []
  (let [input (read-line)]
    (if (= input "quit")
      (println "bye")
      (do
        (println "You said: " input)
        (recur)))))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM