|
<< Index >> |
FutureBasic |
fn <userFunction> | function | |
|
=] fn functionName
[(
param1 [,
param2 ...])
]functionName
, and optionally returns a numeric or string result. The user function must be one which was defined or prototyped at an earlier location in the program. A user function is defined using def fn <protoType>
statement.
If the user function returns a value, you can use fn <userFunction>
as part of a numeric or string expression, as in this example:count = 3 * fn NumFish(x) + 7
fn <userFunction>
as a standalone statement.Formal variable type (in FN definition) | Compatible types (in FN call) |
signed/unsigned byte (var`; var``) | Any numeric expression1,2 |
signed/unsigned short integer (var%;var%`) | Any numeric expression1,2 |
signed/unsigned long integer (var&;var&`) | Any numeric expression1,2 |
pointer variable (p As Pointer [To unType]) | A record variable, or a long-integer expression6 |
single/double precision floating point (var!; var#) | Any numeric expression2 |
string variable(var$) | Any string expression3 |
address reference (@adr&; @p As Pointer [To unType]) | Any variable (of any type), or a long-integer expression preceded by "=".4 |
array declaration (tableau[suffixe](dim1[,dim2...])) | Base array element (arr[suffix](0[,0...]))5 |
fn <userFunction>
are "passed by value." That means that the user function receives a private copy of the parameter's value; if the function changes that copy, it doesn't affect the value of the parameter that was used in the fn <userFunction>
are "passed by reference." That means that the user function receives the address of the parameter that you specified. If the function changes the contents at that address, it will affect the value of the parameter you passed. Parameters are passed by reference when you use the following kinds of formal parameter declaractions in the function definition:p as pointer [to someType]
). (Parameter is passed by reference if you specify a record variable when you call the function.)
@addr; p as pointer [to someType]
). (Parameter is passed by reference if you specify a variable when you call the function.)
arr[suffix](dim1[,dim2...]
))
varptr
function (varptr(var)
or @var
) when you call the function (if you do this, then specify a long integer variable or a pointer variable as the formal parameter in the fn definition). This is another way to give the function direct access to the memory comprising the variable or array, allowing it possibly to change its value.varptr (recVar)
or @recVar
when you call the function).fn <userFunction>
call may appear anywhere below the place where the function is defined (or prototyped). It can appear in the "main" scope of the program, or inside other functions. It may even appear inside the very function that it is calling--this allows you to implement so-called "recursive" functions (functions which call themselves).
See also
local fn; def fn <prototype>