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

Re: [Scheme-reports] 6.1 Exceptions needs examples



I can share my thoughts on this one...

On Wed, 2012-03-21 at 07:49 +0100, Helmut Eller wrote:
> (let ((events '()))
>    (guard (c 
>            (#t #f))
>      (guard (c
>              ((dynamic-wind 
>                   (lambda () (set! events (cons 'c events)))
>                   (lambda () #f)
>                   (lambda () (set! events (cons 'd events))))
>               #f))
>        (dynamic-wind 
>            (lambda () (set! events (cons 'a events)))
>            (lambda () (raise 'error))
>            (lambda () (set! events (cons 'b events))))))
>    (reverse events)) 

Let's keep in mind the text of the standard, which should match that of
R6RS for this case, and therefore, we can test any Scheme implementation
claiming to conform to R6RS to see if we get what we expect.

From the 6th draft, section 4.2.7:

> The body is evaluated with an exception
> handler that binds the raised object to variable and,
> within the scope of that binding, evaluates the clauses as
> if they were the clauses of a cond expression. That im-
> plicit cond expression is evaluated with the continuation
> and dynamic environment of the guard expression. If ev-
> ery cond clause ’s test evaluates to #f and there is no
> else clause, then raise-continuable is re-invoked on the
> raised object within the dynamic environment of the origi-
> nal call to raise except that the current exception handler
> is that of the guard expression.

The important parts here are the dynamic extent in which the COND
clauses are evaluated, and the dynamic extent of the implicit RAISE that
occurs if none of the clauses fire. The extent/continuation of the COND
evaluation is that of the whole GUARD, whereas the re-raise is that of
the original RAISE. 

This means that the first raise will trigger the A and B setters, and
then the C and D setters will trigger. At this point, since the result
is #f, the implementation should re-rais the object from the original
calling extent, thus triggering A and B setters again, before finally
returning without re-entering again. 

This gives '(a b c d a b) as the only valid result. 

-- 
Aaron W. Hsu | arcfide@x | http://www.sacrideo.us
Programming is just another word for the lost art of thinking.

Attachment: signature.asc
Description: This is a digitally signed message part

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