For more information including compatibility, examples and test cases, see https://github.com/petercrlane/r7rs-libs
0.1. Dynamic: (import (slib dynamic))
Provides a kind of name-value store, which can be accessed globally. (This is essentially the same as R7RS parameters, with a different syntax.)
make-dynamic
creates a dynamic object wrapping a given object.
dynamic?
returns true only if the given object is a dynamic.
dynamic-ref
returns the value of a given dynamic object.
dynamic-set!
changes the value of the given dynamic object.
call-with-dynamic-binding
temporarily rebinds a given dynamic
object to a new value within the given procedure.
(let ((x (make-dynamic 'a)) ; <1> (y (make-dynamic 'b))) (dynamic? x) ; <2> (eq? 'a (dynamic-ref x)) ; <3> (eq? 'b (dynamic-ref y)) (dynamic-set! x 'c) ; <4> (call-with-dynamic-binding x 'd ; <5> (lambda () (eq? 'd (dynamic-ref x)))) (eq? 'c (dynamic-ref x))) ; <6>
-
Names
x
as the dynamic object with value'a
-
Returns
#t
asx
is a dynamic object -
Retrieves the value of the given dynamic object, and checks it is correct
-
Changes the value of the given dynamic object
-
Within the
lambda
x
is now bound to'd
-
and
x
reverts to holding'c
after the call