Scheme Procedure: dynamic-wind in_guard thunk out_guard

来源:互联网 发布:神仙劫元神进阶数据 编辑:程序博客网 时间:2024/06/08 13:43

If, any time during the execution of thunk, the dynamic extent of the dynamic-wind expression is escaped non-locally, out_guard is called. If the dynamic extent of the dynamic-wind is re-entered, in_guard is called. Thus in_guard and out_guard may be called any number of times.

          (define x 'normal-binding)          => x          (define a-cont            (call-with-current-continuation             (lambda (escape)               (let ((old-x x))                 (dynamic-wind                     ;; in-guard:                     ;;                     (lambda () (set! x 'special-binding))                               ;; thunk                     ;;                     (lambda () (display x) (newline)                                (call-with-current-continuation escape)                                (display x) (newline)                                x)                               ;; out-guard:                     ;;                     (lambda () (set! x old-x)))))))          ;; Prints:          special-binding          ;; Evaluates to:          => a-cont          x          => normal-binding          (a-cont #f)          ;; Prints:          special-binding          ;; Evaluates to:          => a-cont  ;; the value of the (define a-cont...)          x          => normal-binding          a-cont          => special-binding

原创粉丝点击