; UNWIND-PROTECT, as in Common Lisp, implemented in portable Scheme. ; ; Scheme programmers have been using this macro, and similar macros, ; for more than 20 years. (define-syntax unwind-protect (syntax-rules () ((unwind-protect body cleanup ...) (dynamic-wind (let ((ok? #t)) (lambda () (if ok? (set! ok? #f) (error)))) (lambda () body) (lambda () cleanup ...)))))