Subject: end_of_file and get_char/2

From: José Romildo Malaquias <[email-masked]>
Date: Fri, 5 May 2000 12:01:27 -0300

Hello.

I am writing a little program that will read a text file character
by character and do something with them. I wrote a predicate to
read the file giving its characters as a list. Here it is:

get_file_contents(In,XS) :-
    get_char(In, X),
    (X = end_of_file ->
         XS = []
    ;    get_file_contents(In, XS1),
         XS = [X|XS1]
    ).

read_file(FileName,Cont) :-
  open(FileName, read, Stream, [type(text)]),
  get_file_contents(Stream, Cont),
  close(Stream).

The problem is that get_file_contents is not terminating. When the
stream is at the end, get_char is not unifying X with the atom
end_of_file as described in the standard. Instead it is being
unified to the character ÿ, and keeps reding this character forever,
without seeing the end of the stream.

I have tested the same program with GNU Prolog and it worked as
expected, without any abnormal behaviour. So I believe this is
a bug in SWI Prolog. Has anybody seen it before?

Regards,

Romildo
-- 
Prof. José Romildo Malaquias <[email-masked]>
Departamento de Computação
Universidade Federal de Ouro Preto
Brasil