11.3.13 at_end_of_stream/[0,1] [ISO]

Synopsis

at_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.

Arguments

Stream
stream_object, must be ground

A valid Prolog input stream, defaults to the current input stream.

Description

Checks if 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.

Exceptions

Stream errors (see ref-iou-sfh-est), plus:

existence_error
Some operating system dependent error occurred in reading.

Comments

at_end_of_stream/[0,1] peeks ahead for next input item if there is no item available on the buffer of the specified input stream.

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 end of stream condition is always properly detected, even if that entails blocking until further input is possible, you can use peek_code/[1,2] or peek_byte/[1,2].

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.

See Also

at_end_of_line/[0,1].


Send feedback on this subject.