Re: [Scheme-reports] 4.2.7. Exception Handling Andy Wingo (18 May 2011 14:29 UTC)
Re: [Scheme-reports] 4.2.7. Exception Handling Alaric Snell-Pym (18 May 2011 14:40 UTC)
Re: [Scheme-reports] 4.2.7. Exception Handling Andy Wingo (18 May 2011 15:15 UTC)
Re: [Scheme-reports] 4.2.7. Exception Handling Jim Rees (18 May 2011 16:22 UTC)
Re: [Scheme-reports] 4.2.7. Exception Handling Jim Rees (18 May 2011 16:58 UTC)
Re: [Scheme-reports] 4.2.7. Exception Handling Andy Wingo (18 May 2011 17:35 UTC)
Re: [Scheme-reports] 4.2.7. Exception Handling John Cowan (18 May 2011 19:04 UTC)
Re: [Scheme-reports] 4.2.7. Exception Handling John Cowan (18 May 2011 19:03 UTC)
Re: [Scheme-reports] 4.2.7. Exception Handling Andy Wingo (20 May 2011 10:46 UTC)
Re: [Scheme-reports] 4.2.7. Exception Handling Aaron W. Hsu (20 May 2011 17:02 UTC)
Re: [Scheme-reports] 4.2.7. Exception Handling Andy Wingo (20 May 2011 17:17 UTC)

Re: [Scheme-reports] 4.2.7. Exception Handling Andy Wingo 20 May 2011 09:12 UTC

On Wed 18 May 2011 21:03, John Cowan <cowan@mercury.ccil.org> 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.

  (define-syntax clause-helper
    (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* ...)))))

  (define-syntax guard
    (syntax-rules ()
      ((_ (var clause clause* ...) body body* ...)
       ((call/cc
         (lambda (k)
           (with-exception-handler
             (lambda (err)
               (clause-helper k clause clause* ...))
             (lambda ()
               (lambda () body body* ...)))))))))

Suggestion: that this be a legal implementation of `guard'.

Andy
--
http://wingolog.org/

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