11.2 User-Defined Functions
The DEF statement lets you create your own single-line or
multiline functions.
In BASIC, a function name consists of the following:
Integer function names must end with a percent sign (%),
and string function names must end with a dollar sign ($).
Therefore, the function name can have up to 31 characters.
If the function name ends with neither a percent sign nor a
dollar sign, the function returns a real number.
You can create user-defined functions using these function
naming rules. However, Digital recommends that you use
explicit data typing when defining functions for new program
development. See Chapter 13 for an example of an explicitly
declared function. Note that the function name must start
with FN only if the function is not explicitly declared, and a
function reference lexically precedes the function definition.
DEF functions can be either single-line or multiline.
Whether you use the single-line or multiline format for
function definitions depends on the complexity of the func-
tion you create. In general, multiline DEF functions perform
more complex functions than single-line DEF functions and
are suitable for recursive operations.
If you want to pass values to a function, the function defini-
tion requires a formal parameter list. These formal param-
eters are the variables used to calculate the value returned
by the function. When you invoke a function, you supply an
actual parameter list; the values in the actual parameter list
are copied into the formal parameter at this time. DEF func-
tions allow up to 255 formal parameters. You can specify
variables, constants, or array elements as formal parameters,
but you cannot specify an entire array as a parameter to a
DEF function.