Am So., 9. Okt. 2022 um 11:55 Uhr schrieb Marc Nieper-Wißkirchen
<marc.nie...@gmail.com>:
>
> John Cowan suggested that SRFI 226 should include a version of Common
> Lisp's unwind-protect suitable for Scheme.
>
> In [1], I replied after some discussion with the following proposal
> for a definition of a Scheme unwind-protect:
>
> (define-syntax unwind-protect
>   (syntax-rules ()
>     ((unwind-protect protected-form cleanup-form)
>      (call-with-continuation-barrier
>        (lambda ()
>          (dynamic-wind
>            (lambda () (values))
>            (lambda () protected-form)
>            (lambda () cleanup-form)))))))

I am currently adding unwind-protect to the spec.  The actual
definition should be

(define-syntax unwind-protect
  (syntax-rules ()
    ((unwind-protect protected-form cleanup-form ...)
     (lambda ()
       (dynamic-wind
         (lambda () (values))
         (lambda () (call-with-continuation-barrier (lambda ()
protected-form))))
         (lambda () (values) cleanup-form ...))))))

because there is no reason to protect the cleanup-forms from
call/cc-havoc.  The reason is that these forms are not protected
otherwise as well.

Marc

Reply via email to