[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Scheme-reports] 4.2.7. Exception Handling
On Wed 18 May 2011 21:03, John Cowan <cowan@x> writes:
>> "That implicit `cond' expression is evaluated with the continuation
>> and dynamic extent of the `guard' expression"
> The idea is that "guard" installs a handler which first unwinds and then
> evaluates the cond, rewinding if it doesn't find an appropriate clause.
> This provides termination semantics in the style of C++, Java, C#, etc.
> but with the possibility of carrying on if the guard gets something it
> doesn't expect. If you want instead to get control in the scope of the
> raiser, don't use "guard" but rather "with-exception-handler" to install
> your own handler.
Thanks for the feedback.
To reply in this thread: I still think this rewinding behavior is
suboptimal. It forces implementations to reify full continuations
instead of using one-shot continuations for exceptions.
Here is an implementation of `guard' which does evaluate the predicates
in the raise handler, the bodies with the continuation of the `guard',
and re-raises from within `raise', but without rewinding.
(syntax-rules (=> else)
((_ k) #f) ; fall through to re-raise
((_ k (test) clause ...)
(let ((t test))
(if t (k (lambda () t)) (clause-helper k clause ...))))
((_ k (test => e) clause ...)
(let ((t test))
(if t (k (lambda () (e t))) (clause-helper k clause ...))))
((_ k (test e e* ...) clause ...)
(if test (k (lambda () e e* ...)) (clause-helper k clause ...)))
((_ k (else e e* ...))
(k (lambda () e e* ...)))))
((_ (var clause clause* ...) body body* ...)
(clause-helper k clause clause* ...))
(lambda () body body* ...)))))))))
Suggestion: that this be a legal implementation of `guard'.
Scheme-reports mailing list