Next: , Previous: , Up: Scheme reference   [Contents][Index]


4.8 Parameters

Parameters are Guile’s facility for dynamically bound variables. While parameters are part of the default Guile environment, in Hoot they are provided by the (hoot parameters) module. See the Guile manual for more detailed information.

A parameter is a procedure. To retrieve the value of a parameter, call it with zero arguments. To set a new value, call it with one argument.

(define counter (make-parameter 0))
(counter)    ; => 0
(counter 1)
(counter)    ; => 1
(parameterize ((counter 2))
  (counter)) ; => 2
(counter)    ; => 1
Procedure: make-parameter init [conv (lambda (x) x)]

Return a new parameter whose initial value is (conv init). conv is a procedure of one argument that transforms an incoming value into the value that is actually stored within the parameter. The default conv is an identity function that applies no transformation at all.

Syntax: parameterize ((parameter value) ...) body1 body2 ...

Evaluate body1 body2 … in a context where each parameter is set to its respective value. When control leaves the dynamic extent of the body, each parameter is set back to its previous value.