简体   繁体   English

如何制作Clojure命令行

[英]How to make Clojure command line

I am new to Clojure, I wish to create a command line in clojure. 我是Clojure的新手,我希望在clojure中创建命令行。

I am using lein, The app is simply waiting for user to type something and when press enter, it will print the line. 我正在使用lein,该应用程序只是在等待用户键入内容,然后按Enter键,它将打印该行。

I cannot seems to make Clojure wait forever with lein run Is there any other way? 我似乎无法让Clojure永远lein run还有其他方法吗?

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. 因此,当我键入某些内容并按Enter键时,整个代码就会停止,我想输入用户键入的内容并对其进行连续处理。 I mean each time user press enter, he/she should be able to continue to next line and program will run forever. 我的意思是,用户每次按Enter键,他/她都应该能够继续下一行,并且程序将永远运行。

You need to loop for the user inputs then and provide some means to break the loop (yet, ctrl-c also works). 然后需要循环输入用户输入,并提供一些方法来中断循环(但是,ctrl-c也可以使用)。 Eg 例如

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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