[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] 4.2.7. Exception Handling



I think you're right, and I remember when implementing GUARD for my R6RS noting that it's non-trivial, and now I realize I got the re-raise part wrong. ;-)   The language appears the same, replacing "dynamic environment " with "dynamic extent" for the R7 draft -- I think I prefer the former term though.

But as Alaric noted, it's possible to get it right by saving a continuation in the exception handler before jumping out for the cond clauses.

On Wed, May 18, 2011 at 10:28 AM, Andy Wingo <wingo@x> wrote:
Hi Alaric,

On Wed 18 May 2011 12:19, Alaric Snell-Pym <alaric@x> writes:

> On 05/18/11 09:32, Andy Wingo wrote:
>> The docs for `guard' note that if no cond clause matches, that the
>> exception is re-raised:
>>
>>    "then `raise' is re-invoked on the raised object within the dynamic
>>    extent of the original call to `raise' except that the current
>>    exception handler is that of the `guard' _expression_."
>>
>> But it also notes that the exception handler's continuation and dynamic
>> context are that of the guard _expression_.
>>
>> What does it mean to specify that the object is re-raised from the
>> original `raise' dynamic context?  AFAICS there is no way to know what
>> the dynamic context is at the time of `raise', as the dynamic state is
>> unwound before invoking the handler.
>
> The dynamic state isn't unwound.

Are you sure? :-)  The spec notes:

 "That implicit `cond' _expression_ is evaluated with the continuation
 and dynamic extent of the `guard' _expression_"

and

 "The final _expression_ in a <cond> clause is in a tail context if the
 `guard' _expression_ itself is."

These two sentences indicate to me that my example:

>>    (define p (make-parameter 0))
>>    (define f
>>      (lambda ()
>>        (guard (e ((p)))
>>          (parameterize ((p (+ (p) 1)))
>>            (raise #t)))))

should unwind the dynamic state, and that this program:

 (define p (make-parameter 0))
 (define f
   (lambda ()
     (guard (e ((zero? (p)) (f))
               (else (p)))
       (parameterize ((p 1))
         (raise #t)))))

should never complete (i.e., it should loop indefinitely with no
additional memory consumption).

Andy
--
http://wingolog.org/

_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports

_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports