English
Language : 

NSB8 Datasheet, PDF (79/158 Pages) List of Unclassifed Manufacturers – BASIC interpreter for Z80 family
ITALIAN TECHNOLOGY
grifo®
PASSING VALUES TO USER FUNCTIONS
A DEF statement must includen a list of string and/or numeric variable names, called PARAMETERS
to the function. This parameter list is enclosed in parentheses following the function name. For
example, in the following DEF statement, X$, Y, and Z are parameters to function FNW:
50 DEF FNW(X$,Y,Z)=LEN(X$)+Y+Z
A function call must include a list of string and/or numeric expressions. This expression list is
enclosed in parentheses following the function name. When a function is called, the values of the
expressions in the expression list are assigned, one by one, left to right, to the corresponding variables
in the parameter list of the called function. After this assignment process, the variables named in the
parameter list will contain the corresponding values from the expression list and can be used in the
body of the function in computing the function value.
The number of expressions in the function call’s expression list must match the type of the
corresponding parameter in the parameter list. If the types or number of parameters in the function
definition do not match the types or number of expressions in the function call, an ARGUMENT
MISMATCH ERROR or a SYNTAX ERROR will occur.
NUMERIC PARAMETERS
At function call time, before each numeric variable in the parameter list is assigned its value from
the expression list, the value of the variable is saved by BASIC. When function execution is
completed, the saved values of the numeric variables from the parameter list are restored as the values
of those variables. Thus, the values of the numeric variables from the parameter list after the function
call is completed remain the same as before the function was called. This means that the numeric
parameters of a function may be thought of as separate variables when used during function
execution.
10 DEF FNX(B)=B*3
20 B=2 \ PRINT B
30 PRINT FNX(3)
40 PRINT B
B prints out as 2 before as well as after FNX is called, even though B=3 during the evaluation of FNX
because of the B value of 3 supplied in parentheses in the function call.
STRING PARAMETERS
Unlike those of numeric parameters, the values of string parameters of a function are not saved at
function call time. Thus, after function execution is completed, those variables will retain the most
recent values they acquired during function execution. Note that the assignment of string expressions
to string parameters at function call time follows the same rules as assignment to string variables in
LET statements. In particular, if the string parameter has not been dimensioned as a string variable
before the function call, it will automatically be dimensioned to maximum length of 10.
To contrast the treatment of string and numeric parameters at function call time, try this program:
NSB8
Rel. 5.10
Page 67