[plt-scheme] 369.3

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Jan 13 17:07:38 EST 2007

At Sat, 13 Jan 2007 10:23:44 -0500, Dave Herman wrote:
> > One minor change is that a low-level exception handler, as installed
> > with `call-with-exception-handler', can chain to the "previous" handler
> > by simply returning a value:
> 
> I'm a little confused. It seems very difficult to *prevent* chaining 
> when you don't want it, e.g. to implement `with-handlers'-like behavior 
> (where an inner exception handler whose predicate succeeds overrides any 
> outer exception handlers).

Yes, it's tedious to set up the jumping machinery. `with-handlers' is
almost always the right form to use.

> If I understand what I was doing, I think managed it with a prompt and 
> abort:
> 
>      ...
>      (call-with-continuation-prompt
>        (lambda ()
>          (call-with-exception-handler
>            (lambda (x) (abort-current-continuation tag x))
>            (lambda () (raise 10))))
>        tag
>        (lambda (x) x)))
> 
> AFAICT from macro-stepping, I think that's how `with-handlers' is 
> implemented: install a prompt, invoke the handler, and abort to the 
> prompt if the handler succeeds.
> 
> Is that right?

Yes.

> Why is it that it's legal to abort across the 
> continuation barrier but not to jump across it?

It's a weakness of MzScheme's implementation. To escape across a
barrier, MzScheme needs a prompt --- but `call/cc' can't install a
prompt, because it must call it argument in tail position.

Matthew



Posted on the users mailing list.