Copyright (C) 2000-2012 |
GNU Info (librep.info)Fluid VariablesFluid Variables --------------- Special variables have a number of drawbacks, especially when used in conjunction with the module system (Note: Modules and Special Variables). As a consequence of these drawbacks, `rep' provides a second method of implementing dynamically scoped variables, known as "fluid variables", or just "fluids". A fluid is a first class Lisp object that may be passed around like any other Lisp object. Its sole function is to provide a location from which dynamic bindings may be created. Fluids are anonymous objects, they are usually named by being stored in lexically scoped variables. - Function: make-fluid #!optional value Create and return a new fluid, it will have an initial binding of VALUE (or false if VALUE is undefined). - Function: fluid fluid Return the value of the most recently created binding of the fluid variable object FLUID. - Function: fluid-set fluid value Set the value of the most recently created binding of the fluid variable object FLUID to VALUE. - Function: with-fluids fluids values thunk Call the zero parameter function THUNK (and return the value that it returns) with new bindings created for each of the fluid variables specified in the list FLUIDS. For each member of FLUIDS the corresponding member of the VALUES list provides the initial value of the new binding. If the lists FLUIDS and VALUES are not of the same length, an error is signalled. - Macro: let-fluids bindings body ... A convenient wrapper around `with-fluids', similar to the `let' syntax. The list BINDINGS associates the names of lexical variables containing fluid objects, with the values to bind to those fluid objects. Once the bindings have been installed, the BODY ... forms are evaluated, and the bindings removed. The value of the last of the BODY ... forms is returned. Here is an example code fragment using fluid variables and `let-fluids': (define a (make-fluid)) (define b (make-fluid)) (let-fluids ((a 1) (b 2)) (+ (fluid a) (fluid b))) => 3 automatically generated by info2www version 1.2.2.9 |