On Fri, Mar 20, 2020 at 9:33 AM Shiro Kawai <xxxxxx@gmail.com> wrote:


On Fri, Mar 20, 2020 at 9:17 AM Lassi Kortela <xxxxxx@lassi.io> wrote:

Shouldn't set-position implicitly flush the buffer, and get-position
count only the characters/bytes that the user of the port has already
received from the custom read procedure?

My understanding is that when set-port-position! is called, the port discard the buffered characters,
calls set-position callback, and calls read! callback to repopulate the buffer.

(to be precise, set-port-position! doesn't need to repopulate buffer.   next read operation does it.)

 

Actually, now I realized that textual port must buffer at least one character to support peek-char.

port-position shouldn't change its value depending on whether a character has been peeked form
the port or not; otherwise, a simple routine like "save the position, read ahead something, the restore position"
won't work because it fails if given port has been peeked.