SML / NJ: getting user input

How do I request user input while a function is running?

+4
source share
2 answers

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

TextIO.inputLine TextIO.stdIn 

Clarification: this returns a string option type that is NOT if it is in EOF

+5
source

My code looks something like this:

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

Returns a value of type string option ; usually the line is SOME l , but NONE at the end of the file.

+5
source

Source: https://habr.com/ru/post/1307751/


All Articles