Subject: [SWIPL] at_end_of_stream behaviour.

From: Armando Stellato <[email-masked]>
Date: Thu, 23 Aug 2001 18:49:52 +0200

>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!