Re: [Scheme-reports] Exceptions on JVM [was: Exceptions needs examples] Michael Montague (09 Jan 2014 04:33 UTC)

Re: [Scheme-reports] Exceptions on JVM [was: Exceptions needs examples] Michael Montague 09 Jan 2014 04:28 UTC

On 1/8/2014 6:42 PM, John Cowan wrote:
> Michael Montague scripsit:
>
>> I think this is the issue for Kawa: If all of the clause tests evaluate
>> to false and the 'guard' has no 'else' clause, then 'raise-continuable'
>> is invoked on the raised object within the dynamic environment of
>> the original call to 'raise' or 'raise-continuable'. But the 'guard'
>> clauses are evaluated with the dynamic environment of the 'guard'. If
>> you use an upward continuation to get to the dynamic environment of
>> the 'guard', then you can't get back to the continuation of 'raise'
>> for the implicit 'else' case.
> That's right as far as it goes.  The trouble is that we want guards and
> exception handlers to be able to intercept exceptions thrown in Java code
> as non-continuable Scheme exceptions.  That's why the convolutions
> described in my original message are desirable.

R7RS states that "the (exception) handler is called with the same
dynamic environment as that of the call to 'raise'... How is Kawa making
this happen? Looking in exceptions.scm: 'with-exception-handler'
contains a try-catch so it looks like the exception handlers will be
called in the same dynamic environment as 'with-exception-handler'.

Here is a possible solution:

If exceptions thrown by Java code get turned into Scheme exceptions
before the dynamic environment gets unwound, then it should be possible
to get very close to the full semantics for 'guard' and
'with-exception-handler' without too much overhead. This can be done by
putting try-catch around the <body> of 'parameterize' and 'guard', and
the <thunk> of 'dynamic-wind'.

(define-syntax parameterize
     (syntax-rules ()
         ((parameterize ((param value) ...) . body)
                 <set params to values> (try-catch body (ex (raise ex))))))

The dynamic environment will need to be entirely in Scheme land;
'dynamic-wind' can not use try-finally. In Foment, I use a separate
stack to maintain the dynamic environment and the same idea should work
for Kawa.

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