Previous Up Next

25.5.1  Defining a function with a variable number of arguments

The args command returns the list of arguments of a function.

Note that args() will not work, the command must be called as args or args(NULL). You can also use (args)[0] to get the name of the function and (args)[1] to get the first argument, etc., but the parentheses about args is mandatory.

Examples

testargs():={ local y; y:=args; return y[1]; }:; testargs(12,5)
     
12           

As another example, enter the function:

total():={ local s,a; a:=args; s:=0; for (k:=1;k<size(a);k++) { s:=s+a[k]; } return s; }

then:

total(1,2,3,4)
     
10           

Previous Up Next