Next: Returning Unevaluated Up: Maple Procedures Previous: Types and Map

Variable Number of Arguments: args and nargs

It is possible in Maple for a function to take a variable number of parameters. An example of such a function is the max function. Here is an initial attempt to code up this function


MAX := proc(x1) local maximum,i;
    maximum := x1;
    for i from 2 to nargs do
        if args[i] > maximum then maximum := args[i] fi
    od;
    maximum
end;

The special variable nargs is the number of arguments, and the variable args is a sequence of the arguments, hence args[i] is the 'th argument.


bondaren@thsun1.jinr.ru