Contents | < Browse | Browse >
6B. local and global definitions: scope (DEF)
You may define additional local variables besides those which are
arguments with the DEF statement. The easiest way is simply like:
declares the identifiers a, b and c as variables of your function.
Note that such declarations should be at the start of your function.
syntax: DEF <declarations>,...
declares variables. A declaration has one of the forms:
<var>:<type> where <type>=LONG,<objectident>,...
<var>[<size>]:<type> where <type>=ARRAY,STRING,LIST
(see 8A for more examples, as that is where the types are introduced).
For now, we'll use the <var> form.
Arguments to functions are restricted to basic types; (see 8B ).
A declaration of a basic type can have an initialisation, in the current
version this must be an integer (not an expression):
A program consists of a set of functions, called procedures, PROCs. Each
procedure may have Local variables, and the program as a whole may have
Global variables. At least one procedure should be the PROC main(), as
this is the module where execution begins. A simple program could look like:
DEF a, b /* definition of global vars */
PROC main() /* all functions in random order */
DEF y,z /* possibly with own local vars */
To summarize, local definitions are the ones you make at the start of
procedures, and which are only visible within that function. Global
definitions are made before the first PROC, at the start of your
source code, and they are globally visible. Global and local variables
(and of course local variables of two different functions) may have the
same name, local variables always have priority.