SML/NJ:获取用户输入

发布于 2024-08-29 14:01:17 字数 21 浏览 2 评论 0原文

函数运行时如何提示用户输入?

How do I prompt for user input while a function is running?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

掀纱窥君容 2024-09-05 14:01:17

我的代码看起来像这样:

fun get infile = ( TextIO.output(TextIO.stdOut, prompt)
                 ; TextIO.flushOut(TextIO.stdOut)
                 ; TextIO.inputLine infile
                 )

这返回一个 string option 类型的值;通常在文件末尾有一行 SOME l,但 NONE

My code looks something like this:

fun get infile = ( TextIO.output(TextIO.stdOut, prompt)
                 ; TextIO.flushOut(TextIO.stdOut)
                 ; TextIO.inputLine infile
                 )

This returns a value of type string option; normally a line SOME l, but NONE on end of file.

黯淡〆 2024-09-05 14:01:17

要从标准输入读取一行,请使用 TextIO.inputLine< /a> 来自标准基础库,我认为你可以做一些类似

TextIO.inputLine TextIO.stdIn

澄清的 事情:这会返回一个 string option 类型,如果位于 EOF 则为 NONE

To read a line from standard input use TextIO.inputLine from the Standard Basis Library, I think you can just do something like

TextIO.inputLine TextIO.stdIn

Clarification: this returns a string option type, which is NONE if it is at EOF

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文