next up previous index
Next: The Module Interface Up: Module System Previous: Modules and the

Modules and Source Files

When a source file contains no module directives, it is compiled into the module from which the compilation was invoked. This makes it possible to write small programs without caring about modules. However, serious applications should be structured into modules.

A proper module definition consists of

module interface
starting with a module_interface/1 directive  
module body
starting with a begin_module/1 directive  

Both parts of the module can be in a single file where the interface part is followed by the body part. Alternatively, the interface can be in one file and the body can be spread over one or more additional files, each beginning with a begin_module/1 directive. In this case, the interface file has to be compiled first.

The directive module_interface/1 will first erase the module if it already exists, i.e. remove all items and interfaces contained in the module and then create a new empty module. This is necessary to maintain the integrity of the data and perform a complete recompilation of the module. The module interface contains the declarations and definitions of all modular items which this module shares with other modules that use it. As long as no further module directive occurs, all clauses and queries of the file have this module as definition module. The effect of module_interface/1 ends at the next module_interface/1 or begin_module/1   directive or a the end of the file. If the file contains queries to compile another file containing module directives, this is done and then the module of the current file is resumed.

module/1 in a file is an obsolete shorthand for a module with an empty interface (and it may not be available in future releases).





next up previous index
Next: The Module Interface Up: Module System Previous: Modules and the



Micha Meier
Mon Mar 4 12:11:45 MET 1996