Previous Up

7.4  Less Common Topics

7.4.1  Modules Using Other Languages

Modules created with the module/1 directive 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 Prolog4, 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.

7.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.

7.4.3  Initialization and Finalization

Sometimes modules have global state which needs to 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.

7.4.4  Locking Modules

By default, ECLiPSe does not strictly enforce the hiding of module internals. This facilitates program development as is makes it possible to inspect and trace without being too concerned about module boundaries. E.g. 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/1 which provides a definitive lock, lock/2 which allows subsequent unlocking using a password ( unlock/2), and get_module_info/3 which allows to check whether a module is locked.

Previous Up