www.delorie.com/gnu/docs/guile/guile_304.html   search  
Buy GNU books!

Guile Reference Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

26.9 Dynamic Wind

[FIXME: this is pasted in from Tom Lord's original guile.texi and should be reviewed]

Scheme Procedure: dynamic-wind in_guard thunk out_guard
C Function: scm_dynamic_wind (in_guard, thunk, out_guard)
All three arguments must be 0-argument procedures. in_guard is called, then thunk, then out_guard.

If, any time during the execution of thunk, the continuation of the dynamic_wind expression is escaped non-locally, out_guard is called. If the continuation 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))
			  ;; in-guard:
			  (lambda () (set! x 'special-binding))

			  ;; thunk
		 	  (lambda () (display x) (newline)
				     (call-with-current-continuation escape)
				     (display x) (newline)

			  ;; out-guard:
			  (lambda () (set! x old-x)))))))

;; Prints:
;; Evaluates to:
=> a-cont
=> normal-binding
(a-cont #f)
;; Prints:
;; Evaluates to:
=> a-cont  ;; the value of the (define a-cont...)
=> normal-binding
=> special-binding

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003