You may specify no value for some or all of the arguments to a function or subroutine. What happens in that case depends on the routine or function. Some of the arguments to the routine may be required. If you do not specify a value for such an argument, then an error is generated.
For some of the arguments to a routine a default value may be specified inside the routine. In that case, if the user specifies no value for that argument, then the default value is used instead as if the user specified that value.
Default values can be assigned to arbitrary variables (including
parameters of user-defined subroutines and functions) using either the
default subroutine (default) or the
(defined). For instance,
default,x,2 if not(defined(x)) then x = 2
both assign the value 2 to variable
x if it was undefined before.
x is a pointer (Pointers) or a parameter to a
user-defined subroutine or function, then it is considered to be
undefined if it is ultimately linked to a value that is undefined.
Global variables (Global Variables) are treated in the same way.
Inside a user-defined subroutine or function the parameters of the
routine must be distinguished from the other variables, because we must
be able to tell the difference between the case where the user did not
specify a value for the parameter and the case where the user did
specify a value but the value happens to be undefined. The use of the
defined function as above would return 0 in both of these cases.
DEFINED(x, /TARGET) returns 1 if
x is a pointer, and
x is a parameter to a user-defined function or subroutine for
which the user has specified a value (even if that value happens to be
Consider the following example:
subr foo,x t,defined(x),defined(x,/argument) fie,x endsubr subr fie,a t,defined(a),defined(a,/argument) endsubr
If one executes
foo,5 then one gets
1, 1, 1, 1 as result,
because the parameters
have the value
5. If one executes
undefined, then one gets
0, 1, 0, 1, because a value was defined
for the parameters, but that value is undefined. If one executes
foo without any argument, then one gets
0, 0, 0, 0,
because the user did not specify a value for any of the parameters.
Note that zeros are returned by
fie in this case even though an
fie was specified in
foo: the argument to
foo itself did not have a user-specified value, and
this property is inherited by the parameter of