When defining a function the default value of an input argument can be
specified using the assignment operator =.
When calling a function, the symbol * should be
given to each argument for which default argument value is intended.
For example:
>> f = function (x = 3, y = 5, z = 7) -> w
// define function w = f(x,y,z), with
// default argument values 3, 5, 7
...
end
>> f(*, 10, *) // equivalent to f(3, 10, 7)
Here the default values of the 1st and 3rd arguments are passed to the function.
Function calls don't have to match the signature
of the function definition exactly. To be specific, there are the following
situations.
- If the function call provides fewer arguments than the function definition
requires, the provided arguments will match from the begining of the formal
argument list, and the missing arguments are given the default values.
For example, if f is called by f(3), it is equivalent to
f(3, *, *).
- If the function definition requires only one argument, and a function call
receives more than one arguments, then these arguments are wrapped as a list
and passed to the function.
- If the function definition requires more than one arguments, and a function call
receives only one arguments, and this argument is a list of the same length as
the formal argument list of the function definition, then entries of the
provided argument list will be extracted and passed to the function.
Another fact is that every function argument has a
default default value.
The default default value of an input argument is null
(which is the same as the
empty matrix []).
Of course, unless the function definition code does something to handle
default default value, using it directly will usually cause an error.
oz
2009-12-22