On Jul 12, 2008, at 11:58 AM, Derick Eddington wrote:

> What I want to know is: what is the intended interpretation of the  
> R6RS
> regarding `guard' re-raising exceptions?  I want to know this  
> because I
> want to use continuable exceptions in my libraries which might get  
> used
> with code which might use `guard'.

guard, as it stands, does not distinguish between continuable and
serious conditions, nor does it distinguish between getting called
due to raise or raise-continuable.  What guard does is provide an
alternative expression to be executed should something gets raised
in the body.  If you handle the raised object (i.e., if you have a
test in the guard clause that returns true), then what's happening
is the the subcontinuation from the start of the guard body up to
the call to raise is discarded and the matching consequent of the
guard expression is used in place of the guard.  E.g.,

(guard (c1 [#t 17]) (+ (raise 'hukarez) 12))
=>
17

(guard (c1 [#t 17]) (+ (raise-continuable 'hukarez) 12))
=>
17

Note that execution NEVER returns to the context of the raise or
raise-continuable within the body of the guard expression except
when the guard clauses do not handle the raised object and the
subsequent handler is to be called.  So, it doesn't matter how
the raise was performed if your guard clauses do handle the case.

If you do not handle the raised condition, then basically the
raise was not meant for this guard, and the next outer guard is
tried, until one succeeds:

(guard (c0 [#t 17])
   (+ 9 (guard (c1) (+ (raise 'hukarez) 12))))
=>
17

(guard (c0 [#t 17])
   (+ 9 (guard (c1) (+ (raise-continuable 'hukarez) 12))))
=>
17

Now the issue is what happens if you have installed a handler
that returns:

(define-syntax with-exn-value
   (syntax-rules ()
     [(_ v e)
      (let ([t v])
        (with-exception-handler
          (lambda (con) t)
          (lambda () e)))]))

(with-exn-value 17
   (+ (raise-continuable 'hukarez) 12))
=>
29

(with-exn-value 17
   (guard (c1)
     (+ (raise 'hukarez) 12)))
=>
ERROR: handler returned

(with-exn-value 17
   (guard (c1)
     (+ (raise-continuable 'hukarez) 12)))
=>
ERROR: handler returned

With the change the Derick is raising, the behavior of the
last expression becomes:

(with-exn-value 17
   (guard (c1)
     (+ (raise-continuable 'hukarez) 12)))
=>
29

which does seem like a more reasonable behavior.

I don't see the rationale for using "raise" instead of
"raise-continuable" for re-raising an exception that
was not handled by a guard's clauses.

Aziz,,,


_______________________________________________
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss

Reply via email to