The relation between stream position and end position:
Let S
be a input stream of size n
. Let p
be a position in the source of the stream S
.
- The stream position is
not
end of stream if p < n
.
- The stream position is
at
end of stream if p = n
.
- The stream position is
past
end of stream if p > n
.
On an actual implementation the stream position may be a couple (q,e)
where q
is the position in the source and e
is in {not, at, past}
such that:
- The stream position is
not
end of stream if and only if q < n
and e = not
.
- The stream position is
at
end of stream if and only if q = n
and e = at
.
- The stream position is
past
end of stream if and only if q = n
and e = past
.
This is given by:
7.10.2.13
end_of_stream(E) - If the stream position is end-of-stream then E
is unified with at
...
And with:
7.10.1.1
read - Input. ... input shall start at the beginning of that source.
Knowing this, the stream position is at
end of stream when opening the empty file.
Either stream_property/2
has an issue or the stream is in an invalid state.
A better question could be how is a conforming system supposed to handle end of stream?
And test the empty file and non-empty file for different engines.
On the comment of the question:
There is a note on the standard that the predicate peek_char/2
leaves unaltered the stream position so query like stream_property(S, end_of_stream(Eos0)), peek_char(S, _), stream_property(S, end_of_stream(Eos)), Eos0 = Eos
should succeed.