[plt-scheme] peek-char skip behavior

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Jun 14 07:23:54 EDT 2006

At Wed, 14 Jun 2006 00:17:08 -0400, "David T. Pierson" wrote:
> What is the rationale for peek-char skipping bytes not chars?

N bytes can be skipped in O(1) time, but skipping N character requires
either O(N) work --- as in your implementation --- or some sort of
char-count-to-byte-count cache attached to the port.

I think your `peek-char/skip-chars' is fine for skipping a few
characters. For skipping potentially many characters, shifting work to
the client can often avoid both the O(N) work and the table. For
example, the lexer in "parser-tools" uses `char-utf-8-length' to
accumulate the total byte count as it peeks successive characters.


Posted on the users mailing list.