On 7/19/12, David A. Wheeler <dwhee...@dwheeler.com> wrote:
> Alan Manuel Gloria:
>> IIRC some peek-char implementations are just read-char followed by
>> unread-char, with only one unread-char lookahead: so the sequence of
>> peek-char followed by unread-char might cause strange errors about too
>> many unread-char.
>
> Hmm, I'd think of that as a bug.

Hmm.  Here's an X3J13 Common Lisp issue UNREAD-CHAR-AFTER-PEEK-CHAR:

http://www.lispworks.com/documentation/lw61/CLHS/Issues/iss356_w.htm

Basically the write-up describes peek-char as equivalent to read-char
followed by unread-char.  Meaning that doing an unread-char after a
peek-char is not allowed, as it becomes two unread-char's in sequence.

In fact, I think this restriction goes all the way back to C.  C has
ungetc and getc , but no peekc.  To implement Scheme using FILE*,
you'd implement peek-char as getc followed by ungetc.  Of course
modern Scheme implementations will wrap FILE* if they still use it,
but most Schemes start out as ridiculously simple implementations
(taking advantage of the relative small size of R5RS/R4RS).  Less is
more and all that jazz.

And think about it: R5RS already gives you one character lookahead on
ports.  Your proposed implementation (wrap R5RS port with cons-buffer)
adds another character lookahead buffer, giving a total of 2
characters lookahead.

Still, as long as we require that unread-char is only ever used by the
"." as indentation whitespace implementation, I think it's OK.  I
think it's a slippery slope and you'll have to get more characters of
lookahead, and thus lose strict R5RS-compliance.

--

http://scheme.com/csug8/io.html

Chez Scheme mentions that unbuffered ports have a one-character buffer
in order to support unread-char and peek-char: "When the unbuffered
option is specified, input is unbuffered, but not fully, since one
character of buffering is required to support peek-char and
unread-char."  As the X3J13 UNREAD-CHAR-AFTER-PEEK-CHAR issue points
out, this *probably* ends up meaning that peek-char followed by
unread-char will fail.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Readable-discuss mailing list
Readable-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/readable-discuss

Reply via email to