How do I prompt for user input while a function is running?
Asked
Active
Viewed 3,553 times
2 Answers
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
-
1You might need to valOf the result, as TextIO.inputLine returns a string option. – Martin Törnwall Jul 12 '11 at 19:37
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