common, auto, and readonly parameters

Function parameters can be also declared with keywords common, auto, or readonly in front of the parameter identifier.

A readonly parameter is an attribute of the function that is accessible but not modifiable inside or outside the function. However, its value can be modified by other common or auto parameters.

common and auto parameters are both functions

A common parameter is an attribute of the function that is itself a function. Its value is fixed (to the initial value, which is a function). It is like a utility function which can be used to reset the values of readonly parameters.

An auto parameter is an attribute of the function that is itself a function which takes no input arguments. When the auto parameter is accessed, the function will be called automatically.

The following example will illustrate the uses of various parameters.

polynomial = function [private coeff,
       common  setcoeff = function c -> ()
                             parent.coeff = c;
                          end,
       auto roots = () -> polyroots(parent.coeff)] x -> y

       y = polyeval(coeff, x);
end



oz 2009-12-22