1#lang racket/base 2(require (for-syntax racket/base)) 3 4(provide with-save-and-restore) 5 6(define-syntax (with-save-and-restore stx) 7 (syntax-case stx () 8 [(_ ([id init-val] ...) body0 body ...) 9 (with-syntax ([(old-id ...) (generate-temporaries #'(id ...))] 10 [(new-id ...) (generate-temporaries #'(id ...))]) 11 #'(let ([old-id id] ... 12 [new-id init-val] ...) 13 (dynamic-wind 14 (lambda () (set! id new-id) ...) 15 (lambda () body0 body ...) 16 (lambda () (set! id old-id) ...))))])) 17 18 19