Chawter
10
I
BASIC
Kevwords
DEF
FN
Statement
DEF FNname [(argument
list)]
=expression
Defines
mme
as
a
function according to the
expression.
Name
must be a valid variable name. The type of variable you
use determines the type of value the function returns. For exam-
ple, if you use a single precision variable, the function returns
single precision values. This name, preceded by FN, is the name
of the function when you call it.
Argument list
is
a
list of dummy variables used in
expression.
They are replaced on a one-to-one basis with the variables or
values given when the function is called. If you enter several
variables, separate them with commas. These variables do not
affect variables in your program with the same name.
Expression
defines the operation to be performed.
A
variable
used in
a
function definition may or may not appear in
argument
list.
If it does,
BASIC
uses the value given when the function is
called to perform the function. Otherwise, it uses the current
value of the variable.
Once you define and name a function (by using this statement),
you can use it as you would any
BASIC
function.
Examples
DEF FNR
=
RND (1)*89+10
defines a function FNR to return a random value between 10
and
99.
Notice that the function can be defined with no
arguments.
210 DEF FNW#
<A#,B#)=(A#-B#)*<A#-B#)
220
I#
=
345.998
230
J#
=
150.667
240 T
=
FNW#(I#,J#)
250 PRINT T
defines function FNW# in Line 210 using dummy variables
A#
and
B#.
Line 240 calls the function and replaces variables
A#
and
B#
with variables
I#
and
J#
which are used in the
program.
137