[plt-scheme] Reader too greedy

From: Lauri Alanko (la at iki.fi)
Date: Sun Feb 12 04:35:06 EST 2006

The reader is a bit greedy: when it encounters a special character that
has its own readtable procedure, that character is consumed from the
input before calling the procedure. Also, when the reader encounters an
invalid input character, that character is consumed before raising an

Both of these are a bit annoying, if I need to use that consumed
character as part of normal input. All ports have at least a
one-character peek buffer, so IMHO it should be used in situations like
these: first peek, and only consume if you're going to use it.

The first case cannot really be changed, since it would break all
existing readtable extensions. But it's not a very big deal, since the
procedure gets the initial character anyway and can tack it onto the
input somehow.

But the second case is pretty problematic: if I gather correctly, the
offending character isn't even consistently reported in the
exn:fail:read exception. It is completely lost!

I understand that consuming the offending character is important in
interactive use, since otherwise the REPL would be unusable after a
single syntax error. But there should at least be a parameter to control
this. Otherwise there is no neat way to read an s-expression if there is
one available without scrambling the input even if there isn't.

Also, tacking characters back to the input seems pretty toilsome at the
moment. Sure, I can create my own custom port with a one-character unget
buffer, but this seems redundant. There is scheme_ungetc() already. Why
isn't it accessible from Scheme code?


Posted on the users mailing list.