This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Changing environments



 > at the moment I am trying to implement the procedure (ge <environment>)
 > which should change the current REP loop to the given environment.
 > 
 > The problem is, that I don't know how this could be done.  At the
 > moment an environment is a pair and (<environment-smob> . SCM_EOL) is
 > the top level environment.  I think all I have to do is to create a
 > new top level environment and restart the REPL, no?  Are there any
 > documents that describe the "dynamic root" concept?

the info page below is from an old guile-doc distribution, and may be
out of date.  (you'll probably want to grab the whole thing.)

probably the easiest thing to do is to start another repl on top of the
current one.  if you never want to return to the current one, just use
`(begin (new-repl) (quit))' -- assuming you don't recurse further. :->

thi


---------------------
File: guile-ref.info,  Node: Dynamic Wind,  Next: Threads and Dynamic Roots,  Prev: Dynamic Linking from Marius,  Up: Top

Dynamic Wind
************

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

 - primitive: 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