Next: , Previous: , Up: Programs and Arguments   [Contents][Index]


4.4.4 Parameter lists

(require 'parameters)

Arguments to procedures in scheme are distinguished from each other by their position in the procedure call. This can be confusing when a procedure takes many arguments, many of which are not often used.

A parameter-list is a way of passing named information to a procedure. Procedures are also defined to set unused parameters to default values, check parameters, and combine parameter lists.

A parameter has the form (parameter-name value1 …). This format allows for more than one value per parameter-name.

A parameter-list is a list of parameters, each with a different parameter-name.

Function: make-parameter-list parameter-names

Returns an empty parameter-list with slots for parameter-names.

Function: parameter-list-ref parameter-list parameter-name

parameter-name must name a valid slot of parameter-list. parameter-list-ref returns the value of parameter parameter-name of parameter-list.

Function: remove-parameter parameter-name parameter-list

Removes the parameter parameter-name from parameter-list. remove-parameter does not alter the argument parameter-list.

If there are more than one parameter-name parameters, an error is signaled.

Procedure: adjoin-parameters! parameter-list parameter1 …

Returns parameter-list with parameter1 … merged in.

Procedure: parameter-list-expand expanders parameter-list

expanders is a list of procedures whose order matches the order of the parameter-names in the call to make-parameter-list which created parameter-list. For each non-false element of expanders that procedure is mapped over the corresponding parameter value and the returned parameter lists are merged into parameter-list.

This process is repeated until parameter-list stops growing. The value returned from parameter-list-expand is unspecified.

Function: fill-empty-parameters defaulters parameter-list

defaulters is a list of procedures whose order matches the order of the parameter-names in the call to make-parameter-list which created parameter-list. fill-empty-parameters returns a new parameter-list with each empty parameter replaced with the list returned by calling the corresponding defaulter with parameter-list as its argument.

Function: check-parameters checks parameter-list

checks is a list of procedures whose order matches the order of the parameter-names in the call to make-parameter-list which created parameter-list.

check-parameters returns parameter-list if each check of the corresponding parameter-list returns non-false. If some check returns #f a warning is signaled.

In the following procedures arities is a list of symbols. The elements of arities can be:

single

Requires a single parameter.

optional

A single parameter or no parameter is acceptable.

boolean

A single boolean parameter or zero parameters is acceptable.

nary

Any number of parameters are acceptable.

nary1

One or more of parameters are acceptable.

Function: parameter-list->arglist positions arities parameter-list

Returns parameter-list converted to an argument list. Parameters of arity type single and boolean are converted to the single value associated with them. The other arity types are converted to lists of the value(s).

positions is a list of positive integers whose order matches the order of the parameter-names in the call to make-parameter-list which created parameter-list. The integers specify in which argument position the corresponding parameter should appear.


Next: , Previous: , Up: Programs and Arguments   [Contents][Index]