In article <··············@eho.eaglets.com> , Sam Steingold <···@goems.com>
wrote:
> (defun read-vector (stream char)
> (coerce (read-delimited-list #\] stream t) 'vector))
> (set-syntax-from-char #\[ #\() ; do I really need this?
> (set-syntax-from-char #\] #\)) ; do I really need this?
> (set-macro-character #\[ #'read-vector nil)
> (set-macro-character #\] (get-macro-character #\)) nil)
>
> as expected,
>
> (read-from-string "[1 2 3]") ==> #(1 2 3), 7
> (read-from-string "#\\x") ==> #\x, 3
>
> but:
>
> (read-from-string "[#\\x]") ==>
>
> Error: Meaningless character name x] [file position = 5]
> [condition type: reader-error]
>
> Restart actions (select using :continue):
> 0: Return to Top Level (an "abort" restart)
>
> somehow "]" doesn't terminate the character.
>
> what am I doing wrong?
>
> Thanks.
>
> [I get the error in ACL and CMUCL, but not CLISP, which reads the
> expression as I expect it to.]
Since you've defined #\] as a terminating macro character, it should
terminate the accumulation of the token being read by the #\ reader (which
needs to read past the first character to see whether it's a character
name), then unread the ] and return to the #\ reader. After the #\ reader
returns, the ] will be waiting to be read by read-delimited-list.
At least that's what I understood from reading section 2.2 of the HyperSpec,
and a few related pages.
--
David B. Lamkins <http://www.teleport.com/~dlamkins/>
Wintel is the Yugo of the computer world: cheap to buy, costly to keep.
Sam,
There are a bunch of nonconformances in implementations because READ
efficiency is such a hot-button that vendors may perceive they can't
afford to always conform, I suspect. Genera, for example, used to not even
implement ( and ) as readmacros, so this kind of example would never
work. I had a lot of difficulty setting up examples in the spec as a result
of this ... I don't know if that's been fixed in Genera.
Anyway, I am not sure I even know what to expect since I've always had
the impression that there wasn't agreement among vendors. Maybe that
was just an oddiity of my particular home vendor not supporting it and
me doing an insufficient survey of other vendors though. But as a
result, I'm not sure which to claim is a reference implementation.
I often used to use Genera as a reference implementation, but I always
knew it was not a good reference implementation for this corner of things...
Basically, what you have written seems kinda plausible and you might
just try sending a bug report and see if the vendor either agrees to
change the behavior or explains why they won't.
Incidentally, I don't think you should need the set-syntax-from-char
things. I'm a bit superstitious about those but assume they are more
about "additional magic" that you might not be able to capture in
macro chars... like the special treatment of "." as a consing dot.
That's not what you're trying to do here, so I'd omit those two lines
unless you observe in practice that they matter.