`prev Menu next`

External Function Definition ☆☆
An external function definition begins with EXTERNAL FUNCTION line and ends with END FUNCTION line. An external function definition is written outside of the main program and of any other external procedures. This means that external functions are written below the END line and written not nested.
Example.

    10 DECLARE EXTERNAL FUNCTION P
    20 PRINT P(8,3)
    30 END
    100 EXTERNAL FUNCTION P(n,r)
    110 LET a=1
    120 FOR k=1 TO r
    130    LET a=a*(n-k+1)
    140 NEXT k
    150 LET P=a
    160 END FUNCTION

The portion of from the beginning to the END line, that is, form lines 10 to line 30, is the main program, and the rest is an external function definition.
The EXTERNAL FUNCTION line holds the name of the function and the parameters. Parameters are punctuated by commas and enclosed in parentheses if any. If a function has no parameters, parentheses are not written.
Use a LET statement as in the 150-line, to determine the value. Note that only the function name is written on the left hand side of an equal sign.
Any program unit that contains a reference to an external function other than itself holds a DECLARE EXTERNAL FUNCTION statement as in the 100-line, which notifies the compiler that the name is a function name.
An external function definition has no variables in common with any other program unit. For example, on the above example, even if the main program has variables named n, r, a or k, they are given no influence of invoking the function P.
Note.
If an external function has the same name as a supplied function, the supplied function is valid in the program unit that do not have a DECALARE EXTERNAL FUNCTION that declares the name is that of an external function.
Example.
If the 100-line is omitted in the following program, SQR in the 100 line becomes to mean the supplied function SQR.

    100 DECLARE EXTERNAL FUNCTION SQR
    110 PRINT SQR(4)
    120 END
    200 EXTERNAL FUNCTION SQR(x)
    210 LET SQR=x^2
    220 END FUNCTION