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

Re: [Scheme-reports] 4.2.7. Exception Handling



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