[ Stream I/O | Reference Manual | Alphabetic Index ]
at_eof(+Stream)
Succeeds if the stream Stream is positioned at end of file.
- Stream
- Stream handle or alias (atom)
Description
Used to test if the input stream Stream is positioned at end of file.
-
For file streams and string streams, this means that either the next read
operation will return an end-of-file condition, or end-of-file was already
read and the next read operation would result in a past-end-of-file error.
-
For tty streams, it means only that there is currently no further input
available, and a subsequent read operation will prompt for more.
-
For queue streams, it means only that the queue is currently empty.
The queue will recover from the end-of-file condition when new data
is written into it from the write end.
-
For pipe and socket streams, this condition means that the next read
operation will either block or return an end-of-file condition.
To check whether there is any data to read, use stream_select/3.
-
The null stream is always at end-of-file.
Stream can be a symbolic stream name or a stream handle.
Modes and Determinism
Fail Conditions
Fails if Stream is a file with its pointer not at end of file.
Exceptions
- (4) instantiation fault
- Stream is not instantiated.
- (5) type error
- Stream is instantiated, but not to an atom or a stream handle.
- (192) illegal stream mode
- Stream is an illegal stream mode.
Examples
Success:
at_eof(null).
?- open(file1,update,S), at_eof(S),
write(S,hello), at(S,5), at_eof(S), close(S).
yes.
Fail:
?- open(file1,write,S),write(S,hello), close(S),
open(file1,read,S), at_eof(S), close(S).
no.
Error:
at_eof(X). (Error 4).
at_eof("s"). (Error 5).
at_eof(not_a_stream). (Error 192).
See Also
at / 2, seek / 2, stream_truncate / 1