English
Language : 

NSB8 Datasheet, PDF (80/158 Pages) List of Unclassifed Manufacturers – BASIC interpreter for Z80 family
grifo®
ITALIAN TECHNOLOGY
10 DEF FNQ(X,X$)=ASC(X$)+X
20 X=7 \ X$=”FIRST”
30 PRINT X$,X
40 PRINT FNQ(1,”NEXT”)
50 PRINT X$,X
Note that, although the value of the numeric variable X is saved while the name of X is used for an
argument to FNQ, the same is not true for X$. After the function is evaluated, X$ still retains the value
it was assigned during its use as FNQ argument.
MULTI LINE USER FUNCTIONS
The second type of user function, the multiple line function, permits a value to be computed and
returned by a set of one or more BASIC statements, as opposed to the single expression of the single
line function. The operation and purpose of multi line functions therefore closely parallels that of
subroutines. However, multi line functions permit the easy passing of arguments, and the return of
a single, computed result value.
The definition of a multi line function employs the DEF statement, but without the value equation
necessary to single line function definitions. The DEF statement which begins a multi line function
contains only the keyword DEF, the name of the function, and the list of its parameters:
10 DEF FNM(X,M)
The statements which compute the function value follow this line. When the value has been
computed, a special version of the RETURN statement causes function execution to cease, and
specifies the value to be returned as the function value. Finally, to signal the physical end of the
function definition itself, the FNEND statement is used. As an example, add to the definition of FNM
(started in line 10, above) so that it becomes a function which returns the value of X modulo M, that
is, the remainder generated when X is divided by M:
10 DEF FNM(X,M)
20 IF M<=0 OR M<>INT(M) THEN 40
30 RETURN ABS(X) - (INT(ABS(X) / M)*M)
40 PRINT “ERROR IN MODULO” \ RETURN -1
50 FNEND
In general, multi line functions (as opposed to single line ones) are needed when the algorithm which
computes the function value is too complex to fit on one line as a single expression.
SOME FINAL NOTES
Functions cannot be defined within other functions. One definition must finish before another can
begin. In particular, a FUNCTION DEF ERROR will occur if you forget to include the FNEND
which must conclude every multi line function definition, then, later in the program text, attempt to
define another function.
All user functions must have at least one (1) parameter. It is not necessary to use the parameter in
computation, but it must be a part of the definition, nevertheless.
Page 68
NSB8
Rel. 5.10