﻿ DEF

DEF Statement ☆☆☆

DEF statements enables us to write functions defined by complicated expressions simply as f(x), g(x,y) and so on.
Example.

```10 DEF f(x,y)=x^2+3*y^2
20 FOR x=-4 TO 4
30    FOR y=-4 TO 4
40        PRINT x,y,f(x,y)
50    NEXT y
60 NEXT x
70 END```

Parameters
Variables written in the parentheses succeeding DEF are called parameters.
Any variable which is written in other than the DEF line is a different variable, that is, even if it have the same name as that of a parameter, they have distinct locations on the memory.
Example.

```10 DEF f(x)=x^3
20 LET x=4
30 PRINT f(2)
40 PRINT x
50 END```

Variables x in line 10 and x in line 40 are different.
Thus the PRINT statement in line 40 outputs 4.

Variables in Common
Any variables other than parameters are common among the program unit.
Example.

```10 DEF f(x)=a*x^2+b*x*c
20 INPUT a,b,c
30 PRINT f(1),f(2)
40 END ```

On the above program, variables a, b, c in line 10 and variables a, b, c in line 20 are the same, respectively.

Define a function with no parameter
A function that have no parameter is written without parentheses.
Example.

```10 DEF spot=INT(6*RND+1)
20 FOR i=1 TO 100
30    PRINT spot
40 NEXT i
50 END```

Note.
The result of a DEF statement has the precision of over 16 digits on the decimal operation mode. （not rounded to 15 digits as on a LET statement）

Note.
Functions can not be re-defined during execution as on some interpreter dialect.