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

Re: [Scheme-reports] 6.1 Exceptions needs examples



The following message is a courtesy copy of an article
that has been posted to gmane.lisp.scheme.reports as well.

* John Cowan [2012-03-21 03:28] writes:

> Per Bothner scripsit:
>
>> In an implementation like Kawa without full call/cc support
>> it should still be possible to support "normal" non-continuable
>> exception handling, hopefully in a way that makes use of and
>> integrates with native JVM exceptions.  
>
> I've been thinking about this off and on for some time.  Here are my
> current ideas.
>
> First, a `parameterize` expression has to compile to a try-finally so that
> when the thunk terminates, the parameter will be reset.
>
> A hidden stack (Java or Scheme, doesn't matter) needs to exist which
> holds the handlers.  A `with-exception-handler` call pushes the handler
> itself on the stack, whereas a `guard` expression just pushes a marker
> of some sort.  Again, a try-finally is needed to clean up the stack as
> control exits through it.
>
> On a call to either `raise` or `raise-continuable` the stack is popped.
> If it's a procedure object, apply it to the condition object passed.
> If that returns, either re-raise or return to the caller as the case
> may be.  But if the object on the stack was a marker, wrap the condition
> object in a Java RuntimeException and throw it.  A `guard` expression is
> compiled into a try-catch structure, so it will intercept it.  Likewise,
> `with-exception-handler` catches any RuntimeException and invokes the
> thunk on it.
>
> I hope this makes sense.

What should this example return

(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))

Is it '(a b c d a b) or '(a c d b) or '(a b c d) or unspecified?

Helmut

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