Re: bug in reader?y
Gary Byers <[email protected]> Thu, 29 May 2003 13:15:46 -0600 (MDT)
| Newsgroups | gmane.lisp.openmcl.bugs |
|---|---|
| Message-ID | <[email protected]> |
On Wed, 28 May 2003, Diedrich Wolter wrote:
> Hi!
>
> Using openmcl 0.13.5 I encounter difficulties using self-defined reader
> macros. Within a conditional read that is ignored self-defined reader
> macros do not seem to work. Attached is an example defining a reader
> macro #@ for mac screen points as available in MCL. The error caused by
> the last statement is unclear to me. Is this a bug or am I missing
> something? Any ideas?
>
> Regards,
> Diedrich
>
>
When a form is conditionally skipped (due to a failed #+/#- clause),
what actually happens is that it's read with the special variable
*READ-SUPPRESS* bound to T. When *READ-SUPPRESS* is true, forms
are read more-or-less as normal, but the results are ignored.
Reader macros have to be aware of this, and have to handle the case
where *READ-SUPPRESS* is true specially. So:
(defun point-reader (stream char1 char2)
(declare (ignore char1 char2))
(let ((p (read stream t nil t))) ; eof-errorp t, eof-value nil, recursive-p t
(format t "~%Read ~a" p)
(if *read-suppress*
(values) ; return "nothing"
(logior (first p) (ash (second p) 16)))))
We want to read the form that follows #@ regardless of whether *READ-SUPPRESS*
is true or not, but don't want to make any assumptions about what was
read (or return a meaningful value) unless *READ-SUPPRESS* is false.
In your original function (as in this case), calling READ when *READ-SUPPRESS*
was true returned (NIL NIL). Calling ASH on the second element of that
list - NIL - signaled a TYPE-ERROR.
If there's a bug here, it may be a very obscure one: I'm not sure
whether it's correct for the recursive call to READ to return a list
(NIL NIL) instead of returning no values (which would be indistinguishable
from NIL in this case.) I'd have to check the spec; I'm not sure of that.
>
> ? (set-dispatch-macro-character #\# #\@ #'(lambda (stream char1 char2)
> (declare (ignore char1 char2))
> (let ((p (read stream)))
> (format t "~%Read ~a" p)
> (logior (first p) (ash (second p) 16)))) *readtable*)
> T
> ? #@(8 8)
>
> Read (8 8)524296
> ? #-SOMETHING #@(8 8) #@(9 9)
>
> Read (8 8)
> 524296
> ?
> Read (9 9)589833
> ? #+SOMETHING #@(9 9) #@(8 8)
>
> Read (NIL NIL)
> > Error: value NIL is not of the expected type INTEGER.
> > While executing: ASH
> > Type :POP to abort.
> Type :? for other options.
> 1 >
>
>
>
> --
>
> Diedrich Wolter, [email protected], +49 421 218 9558
> Cognitive Systems Group, University of Bremen
> http://www.cosy.informatik.uni-bremen.de/
>
>
> _______________________________________________
> bug-openmcl mailing list
> [email protected]
> http://clozure.com/cgi-bin/mailman/listinfo/bug-openmcl
>
>