[R6RS] Changing the transcoding mid-stream

dyb at cs.indiana.edu dyb at cs.indiana.edu
Wed Aug 23 14:39:36 EDT 2006


>From Mike:

> From Kent:
> > Good points.  This raises a question: If a call to lookahead-u8 returns
> > eof, and the next operation on the port is a call to get-u8 or
> > lookahead-u8, can the second call return something other than eof if the
> > underlying file (or whatever) has been extended in the meantime?
>
> No.  The EOF is part of the data stream, or at least that was the
> intention.

Also from Mike:

> From Kent:
> > Here's a related question.  I presume that lookahead-char will raise an
> > exception if end-of-file is reached after some but before before enough
> > bytes have been read to make a whole character.  If this exception is
> > caught, the application continues, the underlying file is extended
> > independently with enough bytes to fill out the character, and get-u8 is
> > called again, must get-char also fail with the same exception?
>
> I presume the `get-u8' is really `get-char' and that its invocation is
> the same as the invocation of `get-char'.  In that case, yes, by same
> reasoning about the nature of EOFs as part of the data stream.

This assumes a different model from the one I had in mind, which is that
a port maintains a (probably double) buffer of bytes.  If the buffer is
empty, lookahead-whatever and get-whatever have to make a call into the
O/S to fill the buffer.  If the buffer has characters, but not enough to
read an entire char, lookahead-char and get-char again have to make a call
into the O/S to fill the buffer.  In the former case, the O/S may report
EOF, in which case the operation returns the eof object.  In the latter
case, the O/S may also report EOF, in which case the opertion raises an
exception.  In either case, if the underlying file (or other object) is
extended so that the O/S no longer reports EOF, the next call to either
procedure may complete normally.

I understand you have a model based on infinite streams, but I think my
model should be allowed as well, so I suggest that we not overspecify the
semantics on this edge case.  I can't imagine this will affect many
programs.  Most programs will simply quit trying to read from the port
when the lookahead procedure returns EOF or raise an exception.

Kent



More information about the R6RS mailing list