[plt-scheme] 359.3

From: John Clements (clements at brinckerhoff.org)
Date: Fri Jan 5 18:35:01 EST 2007

On Jan 5, 2007, at 12:56 AM, Lauri Alanko wrote:

> On Thu, Jan 04, 2007 at 08:28:23PM +0800, Matthew Flatt wrote:
>>  (call-with-exception-handler
>>   (lambda (exn) (+ exn 30))
>>   (lambda ()
>>    (call-with-exception-handler
>>     (lambda (exn) (+ exn 3))
>>     (lambda () (raise 10)))))
>>  ; => uncaught exception: 13
>>
>>  (call-with-exception-handler
>>   (lambda (exn) (+ exn 30))
>>   (lambda ()
>>    (list (call-with-exception-handler
>>           (lambda (exn) (+ exn 3))
>>           (lambda () (raise 10))))))
>>  ; => uncaught exception: 43
>
> Is this really a good idea? To my mind, a tail position should only be
> magical with respect to its space usage, not other observable  
> behavior.
>
> Granted, the same thing happens with continuation marks, but at least
> continuation marks aren't implicitly composed together like the
> exception handler is. And when one only accesses the topmost mark, the
> tail calls aren't distinguishable.
>
> So, if the exception handlers really are to be chained together, then
> I think it should be done _always_. This of course means that the body
> thunk cannot and should not be called in a tail position.

I agree that the way that exception handlers replace others in tail  
position is surprising.

However, this solution seems to "have it all," in the sense that:

- exception handlers can be chained, and
- tail calls don't exhaust memory, even when an exception handler is  
placed in the tail-calling procedure, and
- if you want the non-overwriting behavior, you can alpha-expand the  
thunk that is the second argument to call-with exception-handler.

John Clements


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2484 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20070105/8ed58953/attachment.p7s>

Posted on the users mailing list.