Clojure 中如何获取用户输入?
我目前正在学习 clojure,但我想知道如何在 clojure 程序中获取和存储用户输入。 我正在查看 clojure api,发现了一个名为 read-line 的函数,但是我不确定如何使用它(如果它是正确的函数)...
无论如何,如何在 clojure 中获取用户输入?
I'm currently learning clojure, but I was wondering how to get and store user input in a clojure program. I was looking at the clojure api and I found a function called read-line, however I'm not sure how to use it if it's the right function to use...
Anyhow, how do you get user input in clojure ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
read-line
是正确的函数...... .基本上会回显用户输入:
要在 if 语句中使用它,您可能会使用 let:
希望这足以让您开始,因为这大约是我 Clojure 知识的限制!
read-line
is the correct function....would basically echo the users input:
To use it in an if statement, you'd probably use let:
Hope that's enough to get you started, because that's about the limit of my Clojure knowledge!
还要记住,您可以访问所有 Java...
好吧,也许我应该提供一些示例...我的 clojure 技能不好,因此这些示例可能需要一些调整。
System.console() 方式:
BufferedReader 方式:
我的观点是,人们可以在 Clojure 中利用 Java 知识以及 Java 本身。 这是其主要的、广为人知的优势之一。
想知道如果问题是关于 GUI 中的用户输入,我的分数会是多少!
顺便说一句,您可以使用 JOptionPane 建立一个小 GUI 来获取用户输入......
Remember also that you have access to all of Java ...
OK so perhaps I should present some examples ... my clojure skills are not good so these examples may need a bit of tweaking.
The System.console() way:
The BufferedReader way:
My point is that one can leverage knowledge of Java, and Java itself, in Clojure. It's one of its principal, advertised strengths.
Wonder what would my score have been if the question were about user input from a GUI!
By the way, you could use JOptionPane to put up a little GUI to get user input ...
read-line 用于获取用户输入并使用 let 将其绑定到某个变量。
例如:如果你想从用户读取用户ID和密码并显示它,你可以使用下面的代码
read-line is used to get user input and use let to bind it to some variable.
For example : if you want to read user ID and password from user and display it, you could use the following piece of code