Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SML/NJ: getting user input

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

like image 697
john Avatar asked Dec 29 '22 19:12

john


2 Answers

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.

like image 185
Norman Ramsey Avatar answered Jan 19 '23 00:01

Norman Ramsey


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

like image 34
newacct Avatar answered Jan 19 '23 00:01

newacct