Previous Up

8.4  Less Common Topics

8.4.1  Modules That Use Other Languages

Modules created with module/1 automatically import the module eclipse_language, which provides the standard set of ECLiPSe built-in predicates. To create a module that uses a different language dialect, use module/3. For instance

:- module(mystdcode, [], iso).

creates a module in which you can use ISO Standard Prolog,3 but not all of ECLiPSe’s usual language features. Note that the third argument (here iso) simply specifies a library which implements the desired language, so new languages can be added easily.

8.4.2  Creating and Erasing Modules at Runtime

A module can also be created explicitly by a running program with create_module/1 or create_module/3 and erased with erase_module/1. The latter should be used with care, erasing a module while a predicate defined in that module is being executed can provoke unpredictable results. The same holds for trying to erase essential system modules.

8.4.3  Initialization and Finalization

Sometimes modules have global state which must be initialised or finalised. For this purpose, modules can have

Local Initialization Goals:
these are specified as
:- local initialization(Goal).
and are executed just after the module containing them has been loaded.
Exported Initialization Goals:
these are specified as
:- export initialization(Goal).
and are executed whenever the module containing the declaration gets imported into another module. The call will happen in the context of the importing module.
Finalization Goals:
these are specified as
:- local finalization(Goal).
and are executed just before the module containing them gets erased. Modules can get erased either explicitly through erase_module/1 or implicitly when the module is re-compiled, or when the ECLiPSe session is exited. Finalization goals should not do any I/O because in the case of an embedded ECLiPSe, I/O may no longer be available at finalization time.

8.4.4  Locking Modules

By default, ECLiPSe does not strictly enforce the hiding of module internals. This facilitates program development, as it allows the user to inspect and trace without being too concerned about module boundaries. For example, you can set a spy point on a local predicate p/3 in module othermod by calling:

:- spy(p/3)@othermod.

Once a module implementation is stable and there is a need for privacy, it is possible to lock a module. Locking makes it impossible to access internal, local items from outside the module. Of course, the module can still be used though its interface. The built-in predicates related to locking are lock/0 which provides a definitive lock, lock_pass/1 which allows subsequent unlocking using a password ( unlock/2), and get_module_info/3 which allows to check whether a module is locked. lock/0 and lock_pass/1 are usually used as a directive in the source file of the module to be locked.

To the extent implemented by ECLiPSe’s compatibility library.

Previous Up