Next: , Previous: , Up: Arguments   [Contents][Index]


6.4.1.1 Argument Specification

The parameters of a subroutine or function have a definite order. The arguments of the routine can be specified in three ways:

By Position

Any expression can be used as an argument to a routine. Each argument is linked to a parameter of the routine in the order of specification. I.e., the first argument is assigned to the first parameter, the second argument to the second parameter, and so on.

By Keyword Assignment

Some (if any) of the parameters of a built-in routine have a keyword associated with them. You can specify a value for such a parameter by assigning that value to the keyword associated with the parameter. For instance, if the third parameter of routine myfunc() has keyword data associated with it, then myfunc(data=5) assigns the value 5 to that third parameter.

All parameters of user-defined subroutines and functions automatically act as keywords, too. For example, if userfunc() is a user-defined function with parameters x and y, then userfunc(y=3) assigns the value 3 to parameter y.

By Keyword Switch

Some built-in routines have special keyword switches to which no value can be assigned, but which either select or deselect a particular feature of the routine. Specify such a keyword switch by prepending the name of the switch by / if you want to select the corresponding feature, or by /no if you want to deselect the corresponding feature. For instance, differ(x,3) returns the third-order forward difference of array x, and keyword switch /central in differ(x,3,/central) modifies the forward difference to a central difference.

The same notation can also be used for keywords that do accept values (including all parameters of user-defined functions and subroutines). For such a keyword, /keyword is equivalent to keyword=1, and /nokeyword is equivalent to keyword=0.

These three different ways of specifying parameters can be mixed. Keyword switches and keyword assignments can be specified in any order and anywhere between the other types of arguments. Keyword switches are ignored during the assignment of the other arguments to the routine’s parameters. The position of the other types of arguments has no influence on the assignment of arguments-by-position to parameters. For instance, the following function calls are all equivalent (assuming that keyword data is associated with the third parameter):

myfunc(x, y, z, /fast)
myfunc(data = z, x, /fast, y)
myfunc(/fast, x, y, z)

It is illegal to specify more than one value for a single parameter. For instance, the function call myfunc(x, y, z, /fast, data = 5) (with myfunc as described above) is illegal, because two arguments are specified for the third parameter, namely z and 5.


Next: , Previous: , Up: Arguments   [Contents][Index]