From starred@tiscalinet.it Thu Aug 23 18:49:51 2001
Received: from smtp1.libero.it (smtp1.libero.it [193.70.192.51])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f7NGnpb17784
	for <prolog@swi.psy.uva.nl>; Thu, 23 Aug 2001 18:49:51 +0200 (MET DST)
Received: from tiscalinet.it (151.24.144.27) by smtp1.libero.it (6.0.021)
        id 3B8505B5000093FE for prolog@swi.psy.uva.nl; Thu, 23 Aug 2001 18:49:45 +0200
Message-ID: <3B853430.4DC87263@tiscalinet.it>
Date: Thu, 23 Aug 2001 18:49:52 +0200
From: Armando Stellato <starred@tiscalinet.it>
X-Mailer: Mozilla 4.7 [en] (WinNT; I)
X-Accept-Language: en
MIME-Version: 1.0
To: SWI Mailing List <prolog@swi.psy.uva.nl>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Subject: [SWIPL] at_end_of_stream behaviour.

>From the manual:
at_end_of_stream(+Stream)
    Succeeds  after the last character of  the named stream is read,  or

    Stream is not a  valid input stream.

Now look at this procedure:

stream_to_dialog(Dialog_Item,Stream) :-

 \+ at_end_of_stream(Stream),
 repeat,
 write_ln('debug_counter'),
 read_line_to_codes(Stream, Codes),   %transfer a line to Codes
 string_to_list(String, Codes),                % convert Codes to a
String
 send(Dialog_Item,format(String)),        % write String to the editor
fo the dialog.
 at_end_of_stream(Stream),
 !,
 send(Dialog_Item,flush).

The repeat cycle has to stop when all lines from the stream have been
read, (infact at_end_of_stream should succeed and the repeat cycle
stop).
The problem is that at_end_of_stream never succeed and this is not good!
On the last repetition (after having read the last line from the stream)
it fails again and so I've another cycle but this time read_line_to_code
gives an exception:
I/O error in read on stream $stream(7977512) (No such file or
directory).
I've only seen at_end_of_stream succed when the write stream on  side
(let's say) A (i'm working on sockets) has been closed, and the read
stream on side B is open, so i can read from it but it gives me
at_end_of_stream because of the closure of the write stream on side A,
but it doesn't want to behave in the right way in the first case I
exposed.

How can i solve this problem?
Thanx
Armando

P.S.
Another problem: I would like to substitute read_line_to_codes/2  with
read_stream_to_codes/2 (it should remove the problem, infact i would not
be in need of the repeat cycle because read_stream_to_codes/2 should
read all the stream).
But it always says me the same exception as before, though I filled the
stream with something to read!




