Next: mpg-ref-atom, Previous: mpg-ref-at_end_of_line, Up: mpg-bpr [Contents][Index]
at_end_of_stream/[0,1]
ISOat_end_of_stream
at_end_of_stream(+Stream)
Tests whether the end has been reached for the current input stream or for the input stream Stream.
stream_object, must be ground
A valid Prolog input stream, defaults to the current input stream.
Checks whether the end has been reached for the specified input stream. An input stream reaches the end when all items (characters or bytes) except ‘EOF’ (-1) of the stream have been read. It remains at the end after ‘EOF’ has been read.
Stream errors (see ref-iou-sfh-est).
Note that at_end_of_stream/[0,1]
never blocks. If reading ahead
would block, then at_end_of_stream/[0,1]
will fail, even if the
stream is actually at its end. If you want to ensure that the end-of-stream
condition is always properly detected, even if that entails blocking
until further input is possible, then you can use peek_code/[1,2]
or
peek_byte/[1,2]
, e.g. something like the following:
blocking_at_end_of_stream(Alias) :- atom(Alias), stream_property(S, alias(Alias)), !, blocking_at_end_of_stream(S). blocking_at_end_of_stream(S) :- at_end_of_stream(S), !. blocking_at_end_of_stream(S) :- stream_property(S, type(text)), !, peek_code(S, -1). blocking_at_end_of_stream(S) :- stream_property(S, type(binary)), !, peek_byte(S, -1).
This is similar to what SICStus 3 and some other Prolog implementations do.
Please note: The design of
at_end_of_stream/[0,1]
makes it inherently unreliable. It is present only for ISO standards compliance. It is better to read or peek until one of the end of file indications is returned.
at_end_of_line/[0,1]
.