What is a Datum?
A datum is a named location that can contain a value. Most people use the term 'variable', but as a datum can also be a constant ( i.e. cannot be changed once the program starts running ) the term is not strictly accurate. The terms 'constant' and 'variable' will, however, be used where they are applicable. As this document is written in English rather than Latin the word 'datums' will be used as the plural.
Global Datums
A global datum is one that is declared outside a routine definition. It can be always be accessed within any routine defined within the same source file. It is also possible to specify, using the scope marker Public, that is can be accessed from other source files.
The general syntax for declaring a list of global datums is as follows :-
globaldatdecl ::= [ scope ] [ Const ] type datumdecllist ;
The scope specifies from which source files the datums can be accessed. The scope applies to all the datums in the declaration's datum list.
scope ::= Private | Public | Export
Private indicates that the datums can be accessed only within the current source file. This is the default if there is not scope explicitly specified.
Public indicates that the datums can be accessed from any file within the current project ( program or library ).
Export is used when building a library. It indicated that the datums can be accessed from any source file of the project that has loaded the library. If you are building a program rather than a library it will be treated as Public.
The Const keyword indicates that the value assigned when the program starts cannot be changed. Any datum with this attribute should generally have an initialiser expression ( though it is not required ).
The type value will be an existing type that will apply to all the datums in the declaration.
The datumdecllist consists of a comma separated list of the individual datums named in the declaration - including the optional initialisation expressions. This list has the following syntax :-
datumdecllist ::= datumdecl [[, datumdecl ]]
datumdecl ::= datumname [ = expression ]
The datumname is the name that will be used to access the data. It should conform to syntax defined for identifiers. By convention global datum names start with an upper case letter.
The optional expression is used to initialise the datum when the program starts up. If there is no expression the datum will be initialised to the default value - this depend on the data type of the datum.
Here are some examples :-
Number Working; Public Number Counter = 0; Private Const Number MaxAge = 65; Public Point Centre = {20, 20};
Local Datums
Local datums are datums that can only be accessed within a routine. There are two types of local datum. The first are the routine's parameters - these will be dealt with in the section on routines.
The other is the routines local working datums. The syntax is similar to globals.
localdatdecl ::= [ Saved ] [ Const ] type datumdecllist ;
The only real difference is that instead of the optional scope there is an optional keyword Saved. If this is specified then all the values will be saved between calls to the routine.
The rest of the declaration is essentially the same as for global datums. The difference lies in the way the initialisation expression works. For non-Saved datums the expression is evaluated every time the routine is called and the current value of the parameters are used in the calculation. For Saved datums the expression is evaluated once when the program starts - so the expression cannot use any of the parameters or other non-Saved datums.
Graphic Context Datums
The is another class of datum that is used within shapes to control the details of the way things are drawn. These are declared and managed by the system and are covered in detail elsewhere.
Using Datums
Values for datums can be assigned using one of the assignment statements - providing the datum has nor been declare to be a constant. A datum can then be used in any place where a value is expected. It can also be use to match a formal parameter that has be declares as call by reference. In all cases the type of the datum must match the the type of the target.