4.2.2 Call a Method


A method invocation passes control to the called method. Control will normally return to the calling method. An exception handler in the called method may either return to the calling method or raise an exception and begin unwinding the call stack. The call stack will be unwound until the exception is caught by an exception handler or exits the program entirely.


Argument List

A call is coded starting with the Method name followed by an optional argument list. Functions can also be called using the same syntax, but usually they are invoked within an arithmetic expression. A foreign procedure with a mixed case name can be called by quoting its name. Otherwise the Method or Function name is case insensitive.


The argument list may start with one or more switch names denoted by a leading tick. The name of a switch is the name of an Entry parameter with a Bit type. Usually it is most convenient to code switches as the last parameters in a Method.


After optional switches the remaining arguments are separated by commas. Arguments can be called using a keyword prefix with the parameter name followed by an equal sign and the argument value. Using keywords allows parameters to be listed in any order. Otherwize positional arguments are listed in the order corresponding to the parameters in the Method signature. The argument list may start with positional arguments followed by keyword arguments.


A null positional argument is denoted by omitting any value. If the parameter declaration corresponding to a null has a default value, it will be used as the argument value. A compilation error is issued if the parameter declaration has no default value.

Type checking is performed between the listed arguments and the parameters declared in the called module. An argument will be implicitly cast if the corresponding parameter has a different type. The argument to an Entry parameter may be any valid expression cast to the parameter type. An argument to a Change parameter must have the same type as the parameter.

An Exit parameter can be declared as a reference or wizard pointer. An address is returned and stored in the argument which must be a pointer. The argument is coded as an at sign ('@') followed bythe name of the pointer. If the parameter is declared as a wizard then the argument must also be a wizard pointer.


Passing An Array

Arrays may also be passed as arguments by using just the array name as the argument. Arrays are always passed by reference and array data is never copied on a module invokation. The array element type and the size of each dimension must match between the argument and parameter declaration. However the lower bounds can be different constants.


Array parameters can include a length parameter so that procedures can process arrays of varying sizes. The upper bound of an array parameter is designated by a star ('*'). If a name is coded after the star the bound with be stored in a Word variable created with that name. Also see Variable Length Array on the Local Variable Declaration page.

Assign an Expression

If Condition