Re: Transparent wrappers/weak types?

From: Peter Seibel (peter_at_javamonkey.com)
Date: 10/23/04


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


Relevant Pages

  • Summary: System crashing in loop
    ... OBP firmware version. ... but will crash and end up in a state ... The only way out of this loop, is to power off the system ... and restart. ...
    (SunManagers)
  • Re: Do Until... Restart
    ... An IF statement in the loop will do it, with no need to restart ... where I've said Reset B1:B500. ... The macro must run until there are exactly 100 instances of 15 in B1:B500 ...
    (microsoft.public.excel.programming)
  • Restart and Startup Fail Loop
    ... Last Known Good Configuration: Loop continues ... Disable auto restart on Failure: Error Message as follows- ... Re-installing application may fix this problem. ...
    (microsoft.public.windowsxp.general)
  • Re: Restarting a service - help a noob day!
    ... >> Trying to write a vbs to add a printer then stop and restart the spool ... Is there a better way Do loop until maybe. ... >> Pete. ... > If nLoopCount> nLoopMax Then ...
    (microsoft.public.scripting.vbscript)