Original Author Paul Laughton, 2011
Page 76
De Re BASIC!
Each time a function is called from another function a certain amount of memory is used for the
execution stack. The depth of these nested calls is limited only by the amount of memory that your
particular Android device allocates to applications.
Variable Scope
All variables created while running a User-Defined Function are private to the function. A variable
named v$ in the main program is not the same as variable v$ within a function. Furthermore, a variable
named v$ in a recursively called function is not the same v$ in the calling function.
A function cannot access variables created outside of the function, except as parameters passed by
reference. (See Fn.def, below, for an explanation of parameters passed by value and by reference.)
All variables created while running a User-Defined Function are destroyed when the function returns.
When an array variable is destroyed, its storage is reclaimed. However, when a data structure pointer is
destroyed, the data structure is not destroyed (see next section).
Data Structures in User-Defined Functions
Data structures (List, Stack, Bundle, bitmap, graphical object anything referenced through a pointer)
are global in scope. That is, if a variable is used as a pointer to a data structure, it points to the same
data structure whether it is used inside or outside of a function. The data structure may have been
created in the main program, the same user-defined function, or some other user-defined function.
This means that if you pass a pointer to a bundle, for example, and modify that bundle inside the
function, the changes will be retained when the function returns. It also means that a function can
modify graphical objects created outside of the function.
Data structures (List, Stack, Bundle, or graphical object) created while running a User-Defined Function
are not destroyed when the function returns. Local variables that point to the data structures are lost,
but you can return a data structure pointer as the function's return value or through a parameter passed
by reference.
Commands
Fn.def name|name$( {nvar}|{svar}|Array[]|Array$[], ...
{nvar}|{svar}|Array[]|Array$[])
Begins the definition of a function. This command names the function and lists the parameters, if any.
If the function name ends with the $ character then the function will return a string, otherwise it will
return a number. The parameter list can contain as many parameters as needed, or none at all. The
parameters may be numeric or string, scalar or array.
Your program must execute Fn.def before it tries to call the named function. Your program must not
attempt to create more than one function with the same name, or the same function more than once.
However, you may override a built-in function by defining your own function with the same name.