From romildo@urano.iceb.ufop.br  Fri May  5 16:57:01 2000
Received: from urano.iceb.ufop.br (IDENT:root@[200.131.209.253])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id QAA21156
	for <prolog@swi.psy.uva.nl>; Fri, 5 May 2000 16:56:57 +0200 (MET DST)
Received: (from romildo@localhost)
	by urano.iceb.ufop.br (8.9.3/8.9.3) id MAA14860
	for prolog@swi.psy.uva.nl; Fri, 5 May 2000 12:01:27 -0300
Date: Fri, 5 May 2000 12:01:27 -0300
From: =?iso-8859-1?Q?Jos=E9_Romildo_Malaquias?= <romildo@urano.iceb.ufop.br>
To: prolog@swi.psy.uva.nl
Subject: end_of_file and get_char/2
Message-ID: <20000505120127.C11843@urano.iceb.ufop.br>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Mailer: Mutt 1.0.1i

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 <romildo@iceb.ufop.br>
Departamento de Computação
Universidade Federal de Ouro Preto
Brasil

