most errors during reading can be dealt with by preventing them from
happening in the first place. some can't, by virtue of the integrated
parser for symbols and numbers. despite the rather simple protocol, I
have to deal with package errors and numeric errors signaled in this
reader function. the errors are signaled in cases like these:
FOO:BAR (not external)
FOO::BAR (no package)
34/0 (division by zero)
1s999 (range error)
I think an error message should be as complete as possible, so I'd like
to report which unacceptable character string caused the error, but this
has turned out to be excessively hard. also, if there are more errors in
the same list, only the first can be reported, because it's hard to move
past individual elements.
so, my question: should the reader signal errors of type READER-ERROR,
only (which may be augmented to contain the actual string with the
problem), or is it free _not_ to catch any other error that might be
signaled by a function it calls to construct an object?
#:Erik
If you accept this explanation, then, although I'm not completely sure,
I suspect that the current behavior in which the reader does not have to
capture other errors is acceptable. This is because for the purpose of
reading Lisp code, I'm not convinced that a divide by zero that occurs
is really better reported as a reader-error. (You are welcome to
disagree. I don't feel that strongly about this aspect.)
However, while I can accept that the above explanation does reflect the
intent of the design, I don't accept that this is a good thing in
hindsight. I think that having given people a tool which everyone finds
convenient to co-opt for other purposes, we ought to just give up and
accept the fact there is a need for some utility which provides the
capabilities that people need.
Towards this end, I hope that J13 will consider what, if anything, can
be done to make the CL reader more general and suitable for all the
purposes people seem to use it for.
For example, one very simple thing which I found useful was to have a
(setf) READTABLE-PARSE function which, when nil, returns unparsed
strings for each token read instead of interning symbols and trying to
read numbers. This alone gives me 90% of what I want.
A more complex change would be a protocol whereby the function which
actually implements the parser is available directly, and it would allow
different specifications of BNF (or whatever) to be created by the user
and plugged in. A sort of parse-table analogous to read-table. This
gives me the other 90% of what I want. (!)
Would it be sufficient if the reader is defined to do the following:
(A) always use the _most specific_ condition type;
(B) before signalling the error, examine any handlers for that
condition, and signal only if none are available?
In this way, in the normal case (no handlers) the reader would do its
normal signalling of errors (preventing garbage from being read (as far
as it can)), while the programmer would be able to `take over' if
necessary.
Apart from that, I agree with Howard Stearns that it would be
good to have some sort of hook into the reader, after an
extended token is consumed but before the reader attempts to
turn it into a number or symbol. (The information about the way
the reader would treat the token (integer, float, symbol with
or without a package marker, invalid, etc.) could be made available
to the hook. (I believe that it is cheap to determine this
in the course of accumulating the extended token.))
As to the reader evolving into a full-fledged parser, there is
something in CLtL that it was deliberately decided not to go
for such complexity although such implementations had been
in use. (Sorry, don't have the book handy.)
Vassil Nikolov <vnik...@poboxes.com> www.poboxes.com/vnikolov
(You may want to cc your posting to me if I _have_ to see it.)
LEGEMANVALEMFVTVTVM (Ancient Roman programmers' adage.)
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
In the first two cases, it's debatable whether a READER-ERROR or a
PACKAGE-ERROR is signalled. In the last two cases, however, it's definitely
a READER-ERROR, as per CLHS section 2.3.1.1.
Bruno http://clisp.cons.org/~haible/