Warning: This is the manual of the legacy Guile 2.0 series. You may want to read the manual of the current stable series instead.
Next: Parameters, Previous: Critical Sections, Up: Scheduling [Contents][Index]
A fluid is an object that can store one value per dynamic state. Each thread has a current dynamic state, and when accessing a fluid, this current dynamic state is used to provide the actual value. In this way, fluids can be used for thread local storage, but they are in fact more flexible: dynamic states are objects of their own and can be made current for more than one thread at the same time, or only be made current temporarily, for example.
Fluids can also be used to simulate the desirable effects of
dynamically scoped variables. Dynamically scoped variables are useful
when you want to set a variable to a value during some dynamic extent
in the execution of your program and have them revert to their
original value when the control flow is outside of this dynamic
extent. See the description of with-fluids
below for details.
New fluids are created with make-fluid
and fluid?
is
used for testing whether an object is actually a fluid. The values
stored in a fluid can be accessed with fluid-ref
and
fluid-set!
.
Return a newly created fluid, whose initial value is dflt, or
#f
if dflt is not given.
Fluids are objects that can hold one
value per dynamic state. That is, modifications to this value are
only visible to code that executes with the same dynamic state as
the modifying code. When a new dynamic state is constructed, it
inherits the values from its parent. Because each thread normally executes
with its own dynamic state, you can use fluids for thread local storage.
Return a new fluid that is initially unbound (instead of being implicitly bound to some definite value).
Return #t
if obj is a fluid; otherwise, return
#f
.
Return the value associated with fluid in the current
dynamic root. If fluid has not been set, then return
its default value. Calling fluid-ref
on an unbound fluid produces
a runtime error.
Set the value associated with fluid in the current dynamic root.
Disassociate the given fluid from any value, making it unbound.
Returns #t
if the given fluid is bound to a value, otherwise
#f
.
with-fluids*
temporarily changes the values of one or more fluids,
so that the given procedure and each procedure called by it access the
given values. After the procedure returns, the old values are restored.
Set fluid to value temporarily, and call thunk. thunk must be a procedure with no argument.
Set fluids to values temporary, and call thunk.
fluids must be a list of fluids and values must be the
same number of their values to be applied. Each substitution is done
in the order given. thunk must be a procedure with no argument.
It is called inside a dynamic-wind
and the fluids are
set/restored when control enter or leaves the established dynamic
extent.
Execute body body1 body2 … while each fluid is
set to the corresponding value. Both fluid and value
are evaluated and fluid must yield a fluid. The body is executed
inside a dynamic-wind
and the fluids are set/restored when
control enter or leaves the established dynamic extent.
The function scm_c_with_fluids
is like scm_with_fluids
except that it takes a C function to call instead of a Scheme thunk.
The function scm_c_with_fluid
is similar but only allows one
fluid to be set instead of a list.
This function must be used inside a pair of calls to
scm_dynwind_begin
and scm_dynwind_end
(see Dynamic Wind). During the dynwind context, the fluid fluid is set to
val.
More precisely, the value of the fluid is swapped with a ‘backup’ value whenever the dynwind context is entered or left. The backup value is initialized with the val argument.
Return a copy of the dynamic state object parent or of the current dynamic state when parent is omitted.
Return #t
if obj is a dynamic state object;
return #f
otherwise.
Return non-zero if obj is a dynamic state object; return zero otherwise.
Return the current dynamic state object.
Set the current dynamic state object to state and return the previous current dynamic state object.
Call proc while state is the current dynamic state object.
Set the current dynamic state to state for the current dynwind context.
Like scm_with_dynamic_state
, but call func with
data.
Next: Parameters, Previous: Critical Sections, Up: Scheduling [Contents][Index]