;;; -*- Mode: Scheme -*- ;;;; Rewind Protection ;;; (REWIND-PROTECT ) applies the nullary procedure ;;; in the dynamic context of the call to REWIND-PROTECT, ;;; guaranteeing that control enters its extent only once, and that ;;; when control exits, the nullary procedure will be ;;; immediately applied in the dynamic context of the call to ;;; REWIND-PROTECT. ;;; ;;; This procedure needs better a name. The author welcomes ;;; suggestions. See also mit-unwind-protect.scm and ;;; unwind-protect.scm. ;;; ;;; WARNING: You may not use UNWIND-PROTECT within a rewind-protected ;;; extent, because UNWIND-PROTECT arranges for its protector to be ;;; called within the dynamic context of the call to UNWIND-PROTECT. ;;; If UNWIND-PROTECT were called within a rewind-protected extent, ;;; control may need to re-enter the rewind-protected extent to call ;;; the protector, but rewind-protected extents may not be re-entered. (define (rewind-protect thunk protector) (dynamic-wind (let ((entered? #f)) (lambda () (if entered? (error "Re-entering rewind-protected extent.")) (set! entered? #t))) thunk protector))