Calling Functions
Calling Functions
Tacnode allows functions that have named parameters to be called using either positional or named notation. Named notation is especially useful for functions that have a large number of parameters, since it makes the associations between parameters and actual arguments more explicit and reliable. In positional notation, a function call is written with its argument values in the same order as they are defined in the function declaration. In named notation, the arguments are matched to the function parameters by name and can be written in any order. For each notation, also consider the effect of function argument types, documented in Section 9.3.
In either notation, parameters that have default values given in the function declaration need not be written in the call at all. But this is particularly useful in named notation, since any combination of parameters can be omitted; while in positional notation parameters can only be omitted from right to left.
Tacnode also supports mixed notation, which combines positional and named notation. In this case, positional parameters are written first and named parameters appear after them.
The following examples will illustrate the usage of all three notations, using the following function definition:
Function concat_lower_or_upper
has two mandatory parameters, a
and b
. Additionally there is one optional parameter uppercase
which defaults to false
. The a
and b
inputs will be concatenated, and forced to either upper or lower case depending on the uppercase
parameter. The remaining details of this function definition are not important here .
Using Positional Notation
Positional notation is the traditional mechanism for passing arguments to functions in Tacnode. An example is:
All arguments are specified in order. The result is upper case since uppercase
is specified as true
. Another example is:
Here, the uppercase
parameter is omitted, so it receives its default value of false
, resulting in lower case output. In positional notation, arguments can be omitted from right to left so long as they have defaults.
Using Named Notation
In named notation, each argument's name is specified using =>
to separate it from the argument expression. For example:
Again, the argument uppercase
was omitted so it is set to false
implicitly. One advantage of using named notation is that the arguments may be specified in any order, for example:
An older syntax based on ":=" is supported for backward compatibility:
Using Mixed Notation
The mixed notation combines positional and named notation. However, as already mentioned, named arguments cannot precede positional arguments. For example:
In the above query, the arguments a
and b
are specified positionally, while uppercase
is specified by name. In this example, that adds little except documentation. With a more complex function having numerous parameters that have default values, named or mixed notation can save a great deal of writing and reduce chances for error.