SAVE-INPUT and
RESTORE-INPUT allow the same
degree of input source repositioning within a text file as is
available with
BLOCK input.
SAVE-INPUT
and
RESTORE-INPUT "hide the details" of the operations
necessary to accomplish this repositioning, and are used the
same way with all input sources. This makes it easier for
programs to reposition the input source, because they do not
have to inspect several variables and take different action
depending on the values of those variables.
SAVE-INPUT and
RESTORE-INPUT are intended for
repositioning within a single input source; for example, the
following scenario is NOT allowed for a Standard Program:
This is incorrect because, at the time
RESTORE-INPUT is
executed, the input source is the string via
EVALUATE,
which is not the same input source that was in effect when
SAVE-INPUT was executed.
The following code is allowed:
After
EVALUATE returns, the input source specification
is restored to its previous state, thus
SAVE-
INPUT
and
RESTORE-INPUT are called with the same input source
in effect.
In the above examples, the
EVALUATE phrase could have
been replaced by a phrase involving
INCLUDE-FILE
and the same rules would apply.
The standard does not specify what happens if a program
violates the above rules. A Standard System might check for
the violation and return an exception indication from
RESTORE-INPUT, or it might fail in an unpredictable
way.
The return value from
RESTORE-INPUT is primarily
intended to report the case where the program attempts to
restore the position of an input source whose position cannot
be restored. The keyboard might be such an input source.
Nesting of
SAVE-INPUT and
RESTORE-INPUT is
allowed. For example, the following situation works as
expected:
In principle,
RESTORE-INPUT could be implemented to
"always fail", e.g.:
Such an implementation would not be useful in most cases. It
would be preferable for a system to leave
SAVE-INPUT
and
RESTORE-INPUT undefined, rather than to create a
useless implementation. In the absence of the words, the
application programmer could choose whether or not to create
"dummy" implementations or to work-around the problem in
some other way.
Examples of how an implementation might use the return values
from
SAVE-INPUT to accomplish the save/restore function:
These are examples only; a Standard Program may not assume any
particular meaning for the individual stack items returned by
SAVE-INPUT.