Internal Function Definition ☆
Although a DEF statement defines only a function that is represented by an expression, function definitions enables us to define a function by describing the process.
An internal function definition is a function definition written within a program unit. All variables other than the parameters and data written in DATA statements are shared with the program unit.
An internal function definition begins with FUNCTION line and ends with END FUNCTION Line.
A FUNCTION line describes the name and the parameters. Parameters are written punctuated by commas and enclosed in parentheses if any. The rule for naming a function is the same as that of a variable.
To determine the function value, use a LET statement where the function name is written on the left hand side of a equal sign. This type of LET statement is called a function-let-statement.
Example. An internal function definition included by the main program.
10 FUNCTION P(n,r) 20 LET a=1 30 FOR k=1 TO r 40 LET a=a*(n-k+1) 50 NEXT k 60 LET P=a 70 END FUNCTION 80 PRINT P(8,3) 90 END
Note. A function-let-statement is not a LET-statement, and the function name is not a variable on the syntax of Full BASIC. Thus the function value is not rounded to the precision of a variable.
Note. A internal function definition must be written in before the line in which the function is referred. If the function definition is written in after the reference, write a DECLARE FUNCTION statement which holds the name of the function in the beginning.
100 DECLARE FUNCTION P 110 PRINT P(8,3) 120 FUNCTION P(n,r) 130 LET a=1 140 FOR k=1 TO r 150 LET a=a*(n-k+1) 160 NEXT k 170 LET P=a 180 END FUNCTION 190 END