6.17.1 Input Sources

By default, the text interpreter processes input from the user input device (the keyboard) when Forth starts up. The text interpreter can process input from any of these sources:

A program can identify the current input device from the values of source-id and blk.

evaluate ( ... addr u – ...  ) core,block

Save the current input source specification. Store -1 in source-id and 0 in blk. Set >IN to 0 and make the string c-addr u the input source and input buffer. Interpret. When the parse area is empty, restore the input source specification.

source-id ( – 0 | -1 | fileid  ) core-ext,file “source-i-d”

Return 0 (the input source is the user input device), -1 (the input source is a string being processed by evaluate) or a fileid (the input source is the file specified by fileid).

blk ( – addr  ) block “b-l-k”

addr contains the current block number (or 0 if the current input source is not a block).

save-input ( – x1 .. xn n  ) core-ext

The n entries xn - x1 describe the current state of the input source specification, in some platform-dependent way that can be used by restore-input.

restore-input ( x1 .. xn n – flag  ) core-ext

Attempt to restore the input source specification to the state described by the n entries xn - x1. flag is true if the restore fails. In recent (how recent?) Gforth, it is possible to save and restore between different active input streams. Note that closing the input streams must happen in the reverse order as they have been opened, but as long as they are both active, everything is allowed. These Gforth versions only produce non-zero flags as results of catching some exception, and the flag itself is the thrown ball and can be rethrown.

query ( ) core-ext-obsolescent

Make the user input device the input source. Receive input into the Terminal Input Buffer. Set >IN to zero. OBSOLETE: This Forth-94 word has been de-standardized in Forth-2012. It is superceeded by accept.