12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- (define *here* (list #f))
- (define original-cwcc call-with-current-continuation)
- (define (call-with-current-continuation proc)
- (let ((here *here*))
- (original-cwcc (lambda (cont)
- (proc (lambda results
- (reroot! here)
- (apply cont results)))))))
- (define (dynamic-wind before during after)
- (let ((here *here*))
- (reroot! (cons (cons before after) here))
- (call-with-values during
- (lambda results
- (reroot! here)
- (apply values results)))))
- (define (reroot! there)
- (if (not (eq? *here* there))
- (begin (reroot! (cdr there))
- (let ((before (caar there))
- (after (cdar there)))
- (set-car! *here* (cons after before))
- (set-cdr! *here* there)
- (set-car! there #f)
- (set-cdr! there '())
- (set! *here* there)
- (before)))))
|