The reexport declaration comes in three flavours. To reexport the complete interface of another module, use
:- reexport amodule.However, often it is desirable or necessary to restrict the set of reexported items. This can be done in two ways, either by explicitly listing the items to reexport, e.g.
:- reexport useful/3, good/1 from amodule.or else by listing the exception that should not be reexported, e.g.
:- reexport amodule except useless/3, unwanted/1.SpecList can contain any valid export specification, i.e.
:- reexport op(_,_,_) from amodule.To reexport only the operator declaration for the operator 'before', whatever it is defined to, use
:- reexport op(_,_,before) from amodule.or to prevent a macro declaration for internal/3 from being reexported, use
:- reexport amodule except macro(internal/3,_,_).
When explicitly reexporting procedures, it is required that they are actually exported from the other module. In all other cases, the items listed in SpecList do not have to correspond to actually exported items in the other module.
Reexported procedures are made accessible to other modules in the same way as exported ones. That means they can either be called by explicitly qualifying them with the name of the reexporting module (using :/2), or they can be imported from the reexporting module and thus made visible elsewhere.
All the export (and reexport) directive of a module together form what is called the module's interface. The module interface can be extracted from a module source file using the icompile/2 utility from library(document). The interface can also be retrieved from a loaded module by calling get_module_info/3.
Rexporting the same item twice, or reexporting something that has previously been declared imported, is accepted silently.
Reexporting is not compatible with a local definition of the same name (because reexport always implies an import as well), it raises error 92.
The reexport/1 primitive can not only occur as a directive but can also be called at runtime.
% A module that is like m1 but adds something extra: :- module(m). :- reexport m1. :- export extra/1. extra(99). % A module that makes a subset of m1 available: :- module(m). :- reexport m1 except useless/3, unwanted/1. % A module that combines m1 and m2: :- module(m). :- reexport m1 except also_in_m2/2. :- reexport m2. % A module that modifies m1: :- module(m). :- reexport m1 except different/1. :- export different/1. different(better). % Error cases: :- reexport Q. (Error 4). :- reexport p/a. (Error 5). :- local p/1. :- export p/1. (Error 92).