Re: [Scheme-reports] exception handling John Cowan (08 Aug 2011 19:31 UTC)
Re: [Scheme-reports] exception handling Per Bothner (08 Aug 2011 21:12 UTC)
Re: [Scheme-reports] exception handling John Cowan (08 Aug 2011 23:15 UTC)
Re: [Scheme-reports] exception handling Jussi Piitulainen (15 Aug 2011 09:00 UTC)

Re: [Scheme-reports] exception handling Jussi Piitulainen 15 Aug 2011 09:00 UTC

John Cowan writes:
> Per Bothner scripsit:
>
> > Assuming guard is definable in terms of with-exception-handler,
> > there should be a definition in section 7.3 "Derived expression
> > types".
>
> There should, indeed, but no one has written one.  Contributions are
> earnestly solicited.

What about the one in <http://srfi.schemers.org/srfi-34/srfi-34.html>?
Cut-and-pasted from there:

(define-syntax guard
  (syntax-rules ()
    ((guard (var clause ...) e1 e2 ...)
     ((call-with-current-continuation
       (lambda (guard-k)
         (with-exception-handler
          (lambda (condition)
            ((call-with-current-continuation
               (lambda (handler-k)
                 (guard-k
                  (lambda ()
                    (let ((var condition))      ; clauses may SET! var
                      (guard-aux (handler-k (lambda ()
                                              (raise condition)))
                                 clause ...))))))))
          (lambda ()
            (call-with-values
             (lambda () e1 e2 ...)
             (lambda args
               (guard-k (lambda ()
                          (apply values args)))))))))))))

(define-syntax guard-aux
  (syntax-rules (else =>)
    ((guard-aux reraise (else result1 result2 ...))
     (begin result1 result2 ...))
    ((guard-aux reraise (test => result))
     (let ((temp test))
       (if temp
           (result temp)
           reraise)))
    ((guard-aux reraise (test => result) clause1 clause2 ...)
     (let ((temp test))
       (if temp
           (result temp)
           (guard-aux reraise clause1 clause2 ...))))
    ((guard-aux reraise (test))
     test)
    ((guard-aux reraise (test) clause1 clause2 ...)
     (let ((temp test))
       (if temp
           temp
           (guard-aux reraise clause1 clause2 ...))))
    ((guard-aux reraise (test result1 result2 ...))
     (if test
         (begin result1 result2 ...)
         reraise))
    ((guard-aux reraise (test result1 result2 ...) clause1 clause2 ...)
     (if test
         (begin result1 result2 ...)
         (guard-aux reraise clause1 clause2 ...)))))

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