[plt-scheme] current-exception-handler

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Mar 25 08:32:17 EST 2003

On Mar 25, Matthew Flatt wrote:
> At Tue, 25 Mar 2003 04:04:11 -0500, Eli Barzilay wrote:
> > Is there any reason for requiring `current-exception-handler' to
> > escape? 
> 
> Most uses of `raise' are of the form
> 
>   (unless <something>
>     (raise exn))
>   <do normal work, disaster if not <something>>
> 
> but often more embeded in the function. Allowing a return from `raise'
> would therefore require significant work.

This is what I was wondering -- I guess that when there's an
exception, you have to go up the stack for any unwinds, handlers etc,
which means that to jump back in you'll have to use some captured
continuation which makes the whole thing both messy and heavy...  So
maybe the right thing for those cute games is is not the global
exception handler, but some way of affecting what `raise' will do, so
I can do something like

  (current-raise-function
    (let ((old-raise (current-raise-function)))
      (lambda (exn)
        (if (and (exn:application:arity? exn)
                 ...too few arguments `args' for `foo'...)
          (lambda more-args (apply foo (append args more-args)))
          (old-raise exn)))))

But that will probably require rewriting a lot of internal stuff,
since raise can actually return some useful value (like making the
code for function application "return raise ..." instead of just a
raise), which makes this impractical just for the sake of cuteness...
(I can't think of any "real" usage.)


> > BTW#1: is in intentional that (/ 0 0.0) returns 0?
> 
> Yes. This is based on an interpretation of inexact 0.0 as an
> infinite sequence of positive numbers that converge to 0. The same
> interpretation makes (/ 1 0.0) = +inf.0 and (/ -1 0.0) = -inf.0.

(Yeah, I was told that this issue was raised, sorry for my
laziness...)


> > BTW#2: if continuation marks were mutable, wouldn't they be the same
> >        as parameters?
> 
> Yes, when a continuation is restricted to a single thread [...]

But...

On Mar 25, John Clements wrote:
> 
> No, because continuation marks capture the tail behavior of the 
> interpreter.  Consider the following two expressions: [...]

But anyway, I figured out how things stand and got to a conclusion
similar to Matthew's later clarification.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.