[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.12 gauche.parameter - Parameters

Module: gauche.parameter
A "parameter" is basically a stateful procedure that takes zero or one argument. If no argument is given, the parameter returns the current value it is keeping. If single argument is given, it will be the current value of the parameter. Optionally you can give a "filter procedure" that checks the new value before setting it as the parameter value. With the macro parameterize, you can change the parameter's value within certain dynamic scope.

This feature is built in some Scheme implementations, such as ChezScheme, Chicken or MzScheme. This module emulates them.

Function: make-parameter value &optional filter
Creates a parameter whose initial value is value. If an optional argument filter is given, it must be a procedure that takes one argument and returns one value; whenever the parameter's value is about to change, the procedure is called with the given value, and the value the procedure returns will be the parameter's value. The filter procedure can raise an error or reject to change the parameter's value.

Macro: parameterize ((param value) ...) body ...
Evaluages body ..., with change parameter param's value to the given value within the dynamic scope of body .... Returns the value(s) of the result of the last body.

Some examples:
 
(define a (make-parameter 1))
(a) => 1
(a 2)
(a) => 2
(parameterize ((a 3))
  (a)) => 3
(a) => 2



This document was generated by Ken Dickey on November, 28 2002 using texi2html