port positioning [was: last call check]
Per Bothner 05 May 2020 22:21 UTC
I haven't closely followed the discussion, but it seems to me:
The peek-u8/peek-char procedures should work if get-position/set-position! aren't provided.
By the same token, peek-char followed by read-char must not call read! twice and
must not call set-position! (since it may be unavailable).
As noted in previous messages, it followed that an input port must have a
buffer with space for at least 1 byte/chars, along with a count indicating how
may bytes/characters are available.
It follows, for binary input ports:
For peek-u8: If the buffer is empty, call read! to get at least one byte.
If not eof or error return the first byte without making other changes.
For read-u8: If the buffer is empty, call read! to get at least one byte.
If not eof or error, get and remove the first byte in the buffer.
For port-position: Call get-position. Return the result minus
the number of bytes in the buffer.
For textual input ports it is more complicated because the position may be
an opaque object, which means port-position can't just do subtraction.
The main difference is that peek-char must first (if the buffer is empty)
call get-position and stash the position before calling read!.
--
--Per Bothner
xxxxxx@bothner.com http://per.bothner.com/