Spawn a New Function

A function is a value and can be stored in a variable. If f is a function,
g = f;
will create a copy of f and assign it to g. Any modification to g will not affect f. Only functions that have parameters are modifiable. The following code makes a copy of f and then modifies the copy.
f = function [alpha = 1] x -> y
         y = sqrt(x^2 + alpha^2);
    end
g = f;
g.alpha = 5;
Now we have two functions

Any function can act as a prototype and new functions can be ``spawned'' directly from it. The syntax of spawning a new function is

f[parameter_value_1[, parameter_value_2, ...]]
where parameter_value_1 is the value of the first public parameter, parameter_value_2 the value of the second public parameter, etc. The parameter names must appear in the same order as in the original function definition, with non-public parameters skipped. For example
f = function [alpha = 1] x -> y
         y = sqrt(x^2 + alpha^2);
    end
g = f[5];
g will be a function that is the same as f, except that its parameter alpha has value 5.

It's possible to combine function spawning and calling and pass the values of arguments and parameters at the same time. For example

>> f = function [alpha = 1] x -> y
         y = sqrt(x^2 + alpha^2);
   end
>> f[5](3)
   5.830951895

oz 2009-12-22