4

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

ben rudgers
  • 3,647
  • 2
  • 20
  • 32
john
  • 41
  • 1
  • 2

2 Answers2

5

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

ben rudgers
  • 3,647
  • 2
  • 20
  • 32
newacct
  • 119,665
  • 29
  • 163
  • 224
5

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.

Norman Ramsey
  • 198,648
  • 61
  • 360
  • 533