Original Author Paul Laughton, 2011
Page 77
De Re BASIC!
The following are all valid:
FN.DEF cut$(a$, left, right)
FN.DEF sum(a, b, c, d, e, f, g, h, i, j)
FN.DEF sort(v$[], direction)
FN.DEF pi()
% Overrides built-in. You can make = 3!
Parameters create variables visible only inside the function. They can be used like other variables
created inside the function (see Variable Scope, above).
There are two types of parameters: call by reference and call by value. Call by value means that the
calling variable value (or expression) is copied into the called variable. Changes made to the called
variable within the function do not affect the value of the calling variable. Call by reference means that
the calling variable value is changed if the called variable value is changed within the function.
Scalar (non-array) function variables can be either call by value or call by reference. Which type the
variable will be depends upon how it is called. If the calling variable has the "&" character in front of it,
then the variable is call by reference. If there is no "&" in front of the calling variable name then the
variable is call by value.
FN.DEF test(a)
a = 9
FN.RTN a
FN.END
a =1
PRINT test(a), a %will print: 9, 1
PRINT test(&a), a %will print: 9, 9
Array parameters are always call by reference.
FN.DEF test(a[])
a[1] = 9
FN.RTN a[1]
FN.END
DIM a[1]
a[1] = 1
PRINT test(a[]), a[1] % prints: 9, 9
Along with the function's return value, you can use parameters passed by reference to return
information to a function's caller.
Fn.rtn <sexp>|<nexp>
Causes the function to terminate execution and return the value of the return expression
<sexp>|<nexp>. The return expression type, string or number, must match the type of the function
name. Fn.rtn statements may appear anywhere in the program that they are needed.