RE: error in unread-char
Note that it says "is an error" not "will signal an error." In the former
case, an implementation is allowed to do whatever it wants to, including
(correctly or incorrectly) handling it. Only in the latter case can you
rely on a signal in portable code.
I would have to say that the LispWorks implementation is fine from a
language spec point of view, and to be commended for "doing the right
thing" when unreading characters that don't belong on the stream - it
pushes them on the stream which is a great way to handle it.
-----Original Message-----
From: owner-lisp-hug@lispworks.com [mailto:owner-lisp-hug@lispworks.com]
On Behalf Of joshuaaaron@gmail.com
Sent: Monday, October 17, 2005 4:46 PM
To: lisp-hug@lispworks.com
Subject: error in unread-char
Hello all,
I think I've found some behavior in unread-char which
doesn't match the spec (which is a pity, because in this
case I found the actual behavor rather useful).
Consider the following
(with-input-from-string (s "abcdefg")
(read-char s)
(read-char s)
(unread-char #\b s)
(unread-char #\a s)
(read-char s))
In LispWorks:
=> #\a
In CLISP:
=> *** - UNREAD-CHAR from #<INPUT STRING-INPUT-STREAM> without
READ-CHAR before it
and the docs state
"It is an error to invoke unread-char twice consecutively on the same
stream without an intervening call to read-char (or some other input
operation which implicitly reads characters) on that stream."
of which I must admit, this is a case.
Also of note (which I just discovered), it doesn't seem to matter
whether or not the
arg to unread char was actually the last unread char. And, there seem
to be two distinct
behaviors in LW.
(with-input-from-string (s "abcdefg")
(read-char s)
(read-char s)
(unread-char #\x s) ;; not #\b
(unread-char #\k s) ;; not #\a
(read-char s))
=> #\a ;; magic !
However, in a listener, I seem to be able to unread whatever I want. E.g.
CL-USER 12 > (unread-char #\h)
#\h
CL-USER 13 > h ;; I didn't insert this h
Any thoughts? I'm on LWM 445, Mac OS X 10.4.2
--
=====================
Joshua Taylor
tayloj@rpi.edu