The Smurf programming language specification contains just a single line referring to input methods:
i - takes a string from user input, and places it on the stack.
This line does not clearly define how the string is obtained. There are four basic options; from most common to rarest, these are:
- Non-interactive input
- All input is provided non-interactively before the program is executed, and no new input can be provided after the program has begun to run. The string produced by the first occurrence of the ‘i’ command is the entire input given. Further occurrences of the ‘i’ command return the empty string. This is equivalent to passing a string parameter to a shell command.
- String-buffered input
- Input is provided interactively, as much as possible at a time. Text typed by the user is stored in a buffer and when the ‘i’ command is encountered the string produced consists of the contents of the buffer, which is then emptied. If the buffer is empty, the ‘i’ command returns the empty string. This is equivalent to the behaviour of standard input on many systems.
- Line-buffered input
- Input is provided interactively, a line at a time. Text typed by the user is stored in a buffer and when the ‘i’ command is encountered the string produced consists of the text up to, but excluding, the first newline in the buffer; the newline is then removed from the buffer. If the buffer does not contain a newline then the program waits for a newline to be entered before execution continues. This is equivalent to the behaviour of input commands in programming languages such as many dialects of BASIC.
- Character-buffered input
- Input is provided interactively, a character at a time. Text typed by the user is stored in a buffer and when the ‘i’ command is encountered the string produced consists of the first character in the buffer; this character is then removed from the buffer. If the buffer is empty, the ‘i’ command returns the empty string. This input mode exists only for ease of programming, and should generally be avoided.
As the non-interactive and string-buffered input methods are the only input methods in common use, programs using these input methods can be referred to as ‘non-interactive’ and ‘interactive’ respectively. The description accompanying a Smurf program should specify which input method it requires. The documentation for a Smurf interpreter or compiler should specify which input methods it supports; ideally an interpreter or compiler should support both non-interactive and interactive input methods.