DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

(guile.info.gz) Dynamic Wind

Info Catalog (guile.info.gz) Error Reporting (guile.info.gz) Control Mechanisms (guile.info.gz) Handling Errors
 
 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))
           		       (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
 
Info Catalog (guile.info.gz) Error Reporting (guile.info.gz) Control Mechanisms (guile.info.gz) Handling Errors
automatically generated byinfo2html