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]

Re: dynamic Bindings


> What does it mean "currently"? Will there be something different in the
> future?

My preference is thread-safe version of "fluid-let", which is in MIT Scheme,
RScheme, and that I am adding to Kawa:

     - special form+: fluid-let ((VARIABLE INIT) ...) EXPRESSION EXPRESSION
          ...
     The INITs are evaluated in the current environment (in some
     unspecified order), the current values of the VARIABLEs are saved,
     the results are assigned to the VARIABLEs, the EXPRESSIONs are
     evaluated sequentially in the current environment, the VARIABLEs
     are restored to their original values, and the value of the last
     EXPRESSION is returned.

The implementation model is that each thread has a list of dynamic
bindings.  Dynamic references (and set!) are serched in that list.
When a new thread is created, the current value of the dynamic binding
list in the parent thread becomes the initial value of the new thread's
dynamic binding list.  Fluid-let is defined thus:

   (let ((old-bindings (%get-current-dynamic-binding-list))
	 (new-bindings (cons 'VARIABLE (cons INIT (... old-bindings)))))
     (dynamic-wind
        (lambda () (%set-current-dynamic-binding-list new-bindings))
	(lambda () (begin EXPRESSION EXPRESSION ...))
        (lambda () (%set-current-dynamic-binding-list old-bindings))))

	--Per Bothner
Cygnus Solutions     bothner@cygnus.com     http://www.cygnus.com/~bothner