From: ....What Is?....
Subject: Errors in the Lisp reader
Date: 
Message-ID: <16803@life.ai.mit.edu>
I'm writing a program that takes another as input, and I want to use
the Lisp reader, since it would simplify my task enormously.  The
problem is if the program it's reading has anything that normally
causes the Lisp reader to generate an error, it will take my program
with it.  Is there any way to have the Lisp reader pass back a flag
or maybe multiple values to let me control the errors?

This sounds like a FAQ, so if there's a FAQL out there I'd appreciate
it, and it'd probably cut down on my questions. :)

--
Steve Boswell         | This opinion is distributed in the hopes that it
······@ucsd.edu       | will be useful, but WITHOUT ANY WARRANTY...
······@gnu.ai.mit.edu |

From: Barry Margolin
Subject: Re: Errors in the Lisp reader
Date: 
Message-ID: <1991Jul7.175553.7720@Think.COM>
In article <·····@life.ai.mit.edu> ······@wookumz.gnu.ai.mit.edu (....What Is?....) writes:
>I'm writing a program that takes another as input, and I want to use
>the Lisp reader, since it would simplify my task enormously.  The
>problem is if the program it's reading has anything that normally
>causes the Lisp reader to generate an error, it will take my program
>with it.  Is there any way to have the Lisp reader pass back a flag
>or maybe multiple values to let me control the errors?

You use the same error handling mechanism that you'd use for anything else.
If the Lisp you're using implements the CL condition system, you can use
that to catch errors.  Unfortunately, I don't think the precise type of
error that the reader signals was specified in CLtL2; I think we may have
since defined something like PARSE-ERROR or READER-ERROR.  You're probably
going to have to handle something very general, such as ERROR, to be at all
portable.
-- 
Barry Margolin, Thinking Machines Corp.

······@think.com
{uunet,harvard}!think!barmar
From: Todd Kaufmann
Subject: Re: Errors in the Lisp reader
Date: 
Message-ID: <TODD.91Jul9151559@as03.atr.co.jp>
In article <·····@life.ai.mit.edu> ······@wookumz.gnu.ai.mit.edu (....What Is?....) writes:
   Summary: How to control them?

   I'm writing a program that takes another as input, and I want to use
   the Lisp reader, since it would simplify my task enormously.  The
   problem is if the program it's reading has anything that normally
   causes the Lisp reader to generate an error, it will take my program
   with it.  Is there any way to have the Lisp reader pass back a flag
   or maybe multiple values to let me control the errors?


re: CommonLisp:
See the section on CONDITIONS in CLtLii, specifically section 29.3.2.
Example:
 (let* ((error-val (gensym))
	(result (handler-case (read stream nil stream)
			      (error (condition)
				     error-val))))
    (if (eq result error-val)
	(print "an error occurred..")
	..))
is one possible way.  Note I use a gensym here for error-val to get a
unique value that can in no way be generated by the read form (even if it
uses #. syntax).  Using the stream itself will also work; it is often used
as a handy eof-value (like here), since it can't be read as a form (barring
#.trickery).

Also the value of *read-suppress*, which will keep nasty things like #.form
from biting you.

You can also handle/define more specific errors using conditions, as well
as restarts.

Not all CL's will have it yet (it's part of the X3J13 draft), but LUCID and
ALLEGRO should; maybe not exported by default.  Use
(mapcar #'symbol-package (find-all-symbols "HANDLER-CASE")) so find the
package it's in.


re: EmacsLisp:
There is a similar function.. see the section on conditions/signal in the
Emacs Lisp manual.

 -todd

ATR Interpreting Telephony Research Laboratories
Sanpeidani Inuidani,  Seika-cho Soraku-gun,  Kyoto 619-02  Japan
email: ····@atr-la.atr.co.jp, ····@cs.cmu.edu
 +81 - 7749 5 1340     fax: +81 - 7749 5 1308