67
DEF FN Directive
Define Function
Formats
1. Single Line: DEF FNname[$]([LOCAL ]argvar1[,argvar2, ... ])=expression[$]
2. Multi-Line: DEF FNname[$]([LOCAL ]argvar1[,argvar2, ... ])
RETURN expression[$]
END DEF
Where:
argvar ...
Comma-separated list of variables that correspond to arguments
passed to the function or returned in the expression.
expression[$] String or numeric expression. In multi-line functions the
expression is the value returned. In single-line functions, the
expression defines the value of the function.
FNname[$]
Name of the function with FN prefix. Use a valid string or numeric
variable name, e.g., FNX or FNABC$.
LOCAL
Optional keyword. Indicates that an argument variable is local to
the function. Use LOCAL to prevent permanent changes to program
variables. ProvideX defers processing the LOCAL clause in functions
until all arguments are parsed.
Description
Use the DEF FN directive to define single- or multi-line functions. These functions
are considered string or numeric depending on the type of variable used in the
function name.
In Execution mode, ProvideX skips past the function without executing it. ProvideX
resumes after the DEF FN directive, executing the rest of the code until it reaches the
statement that invokes FNname( )... whereupon it applies the defined function.
Format 1: Single Line Function
DEF FNname[$]([LOCAL ]argvar1[,argvar2, ... ])=expression[$]
In a single-line function assignment, expression defines the value to be returned by
the function. Include the optional keyword LOCAL to define argument variables as
local.
Examples
0010 DEF FNX(A,B)=A^B
0020 LET A=1, B=2
0030 PRINT A,B,FNX(3,4),A,B
0040 STOP
->RUN
1 2 81 3 4