Re: Transparent wrappers/weak types?
From: Peter Seibel (peter_at_javamonkey.com)
Date: 10/23/04
- Next message: David Golden: "Re: Newbie question: how to save file in lisp(cmucl)"
- Previous message: Matthew Danish: "Re: Newbie question: how to save file in lisp(cmucl)"
- In reply to: Barry Margolin: "Re: Transparent wrappers/weak types?"
- Next in thread: Adam Warner: "Re: Transparent wrappers/weak types?"
- Reply: Adam Warner: "Re: Transparent wrappers/weak types?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 23 Oct 2004 18:42:35 GMT
Barry Margolin <barmar@alum.mit.edu> writes:
> In article <pan.2004.10.23.05.39.03.187825@consulting.net.nz>,
> Adam Warner <usenet@consulting.net.nz> wrote:
>
>> Hi all,
>>
>> If I wrap an object in a structure S can code continue to run
>> seamlessly by wrapping the code in a TYPE-ERROR handler that checks
>> if the object causing the type error is of type S and if so returns
>> the object itself?
>>
>> For example, the goal is to have this code run without error by
>> only wrapping code around the LOOP:
>>
>> (defstruct wrapped list)
>> (defparameter *list* (make-wrapped :list '(1 2 3)))
>>
>> (loop for item in *list* do (print item))
>>
>> When the type-error of *list* is encountered in the loop the error
>> handler should return the value (wrapped-list *list*) for
>> processing to continue.
>
> I think this could only be expected to work if none of the code that
> makes use of wrapped objects is compiled with low safety. Otherwise,
> they wouldn't be required to do type checks, and undefined behavior
> results.
Also, even if the error is signaled, you won't have restarts at the
appropriate level of granularity to recover. For instance in this
case, to "fix" the type error you need a way to restart the LOOP
having replaced *list* with the wrapped list. What you really want is
for LOOP to have established a USE-VALUE restart around the right bit
of code so you can replace the mistyped object (i.e. *list*) with an
object of the right type and let LOOP proceed. But there's no such
restart documented as part of LOOP.
You say "the error handler should return the value ...". But that's
wrong--handlers don't handle errors by returning values; they handle
them by causing a non-local exit. Such as invoking a restart.
-Peter
--
Peter Seibel peter@javamonkey.com
Lisp is the red pill. -- John Fraser, comp.lang.lisp
- Next message: David Golden: "Re: Newbie question: how to save file in lisp(cmucl)"
- Previous message: Matthew Danish: "Re: Newbie question: how to save file in lisp(cmucl)"
- In reply to: Barry Margolin: "Re: Transparent wrappers/weak types?"
- Next in thread: Adam Warner: "Re: Transparent wrappers/weak types?"
- Reply: Adam Warner: "Re: Transparent wrappers/weak types?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|