Contents | Prev | Next | Index
A local module is a collection of declarations of constants, types, variables, modules and procedures, and a sequence of statements. They are enclosed in brackets MODULE and END. The module heading contains the module identfier, and possibly a number of import lists and an export list. An import list specifies all identifiers of items that are declared outside but used within the module and therefore have to be imported. The export list specifies all identifiers of items declared within the module and used outside. Hence, a module constitutes a visibility wall around its local items whose transparancy is strictly under control of the programmer.
Items local to a module are said to be at the same scope level as the module. They can be considered as being local to the procedure enclosing the module but residing within a more restricted scope. The module identifier is repeated at the end of the declaration.
module_decl ::= MODULE loc_mod_id priority ; import_list export block <identifier> loc_mod_id ::= <identifier> priority ::= [ const_expr ] ::= <empty> export ::= EXPORT QUALIFIED ident_list ; ::= EXPORT ident_list ; ::= <empty> |
The statement sequence which constitutes the module body is executed when the procedure or compilation unit to which the module is local is called. If several modules are declared, then these bodies are executed in the sequence in which the modules occur. These bodies serve to intialize local variables and must be considered as prefixes to the enclosing procedure's or compilation unit's statement part.
If an identifier occurs in the import (export) list, then the denoted item may be used inside (outside) the module as if the module brackets did not exist. If, however, the symbol EXPORT is followed by the symbol QUALIFIED, then the listed identifiers must be prefixed with the module's identifier when used outside the module. Such a qualified export serves to avoid clashes of identical identifiers exported from different modules and presumably denoting different items.
A module may feature several import lists which may be prefixed with the symbol FROM and a module identifier. The FROM clause has the effect of unqualifying the imported identifiers. Hence they may be used within the module as if they had been exported in a normal, non-qualified mode.
If a record-type is exported, all its field identifiers are exported too. The same is true for the constant identifiers in the case of an enumeration-type.
A module with an explicit priority causes its nested procedures and module code to be executed in a synchronized mode. Its procedures are declared with the JAVA SYNCHRONIZED modifier. The priority number is being used to temporarily change the current thread's priority inside the module.
Contents | Prev | Next | Index
Canterbury Modula-2 for Java (Last documentation update
Feb 8, 2000)
Copyright © 1998 Mill Hill &
Canterbury Corporation, Ltd. All rights reserved
Please send any comments or corrections to
mhc@webcom.com