Search code examples
prologiso-prolog

End_of_stream property after opening empty file


I'm running the following query in a directory having an empty file empty:

?- member(EOF_action,[error,eof_code,reset]),
   open(empty,read,S,[eof_action(EOF_action)]),
   stream_property(S,end_of_stream(EOS)),
   close(S).

Here's what I get from different Prolog systems:

Prolog system eof_action(error) eof_action(eof_code) eof_action(reset)
SICStus Prolog not not not
GNU Prolog at at not
Scryer Prolog at at at
Traella Prolog at at not
SWI-Prolog not not not

It appears that above systems behave quite differently in this particular corner case.

Does the ISO-Prolog standard specify which behaviour is right for conforming processors?


Solution

  • 7.10.2.9 End position of a stream
    When all a stream S has been input (for example by
    get_byte/2 or read_term/3) S has a stream position
    end-of-stream. ...

    Does this include empty files, where nothing has been input, although nothing is all we have? Thinking of VSAM ... This remains pretty ambiguous no matter how we twist and turn it.

    More important is what happens if we peek_char/1 or get_char/1 any further.

    And even worse whether or not at_end_of_stream/0/1 and stream_property(S, end_of_stream(Eos)) are the same, at least for detecting the end the first time.

    As a quick check enter

    ?- at_end_of_stream.
    

    (There are two factions, two who fail and those who prompt. In the past there was much more prompting)