Next: Function Declarations, Up: Functions [Index]
A function is defined by its type, name, list of arguments and body. The function introductory syntax has the elements appearing in order.
Exception is taken for functions evaluating to function pointers, that, just like function pointers themselves, have the name and list of arguments embedded in the evaluation type.
Both the simple (i.e. non function pointer) type and the function name are plain aime identifiers.
The arguments list is introduced by the literal (, followed by parameter declarations separated by commas and concluded by the literal ).
Like other variables, function parameters are declared by type and name (function pointer parameters follow the function pointer declaration syntax).
Like other variable declarations, a subsequent parameter may have the type omitted, with the last seen parameter type used instead.
void parameters_1(integer a, b, c) { return a + b + c; }
void parameters_2(text d, e, real f) { return a + b + c; }
If the parameter is a function pointer, the outer most (single word) type may be omitted in favor of the last seen outer most (single word) type.
A special parameter syntax has both the type and the name omitted.
See Typeless Anonymous Arguments Functions.
The function body is a sequence of instructions (in effect, a non procedural program itself) surrounded by braces (the { and } literals).
Unless the function evaluates to no value (i.e. the improper ‘void’ type), the last instruction gives the evaluation value. It ought to be a simple (i.e. not compound) one. It may be led by the keyword ‘return’.
# a string length function integer values_1(text a) { return length(a); }
# and a second one integer values_2(text a) { ~a; }
Next: Function Declarations, Up: Functions [Index]