[ Modules | Reference Manual | Alphabetic Index ]

export ++SpecList

Exports from the caller module all items specified by SpecList.
One or a comma-separated sequence of valid export specifications


To make definitions from one module accessible in others, they have to be exported. The following type of items can occur in SpecList and can thus be exported:
procedure specification
domain declaration
structure declaration
operator declaration
character class declaration
syntax option setting
macro (input transformation) declaration
portray (output transformation) declaration
initialization goal specification
SpecList is a comma-separated sequence of one or more of such items. The export/1 primitive usually occurs as a directive in compiled module files. It can occur anywhere in the file.

Exporting Procedures

A procedure can be (and usually is) declared as exported before it is actually defined. Export declarations should occur either at the beginning of a module text, or just before the procedure definition, e.g

       :- export double/2.
       double(X, Y) :-
	   Y is 2*X.

You can only export procedures that are defined in the exporting module. Imported procedures cannot be exported with export/1 (it raises error 94) - use reexport/1 to do this.

Declaring a procedure as exported will make it accessible to other modules. That means that it can either be called with explicit module qualification using :/2, or it can be imported and thus made visible elsewhere.

Procedures can be imported and calls to them compiled before they have been exported, e.g. when an importing module is compiled before the exporting module. This mechanism should be used only in exceptional situations, normally the exporting module should be compiled first. The reason is that the compiler needs some information about the predicate when compiling a call to it. If this information is not available at call time, an incompatibility may occur later when the exported definition is encountered.

Exporting Other Declarations

Exported structure, operator, syntax, macro and portray declarations have the same effect as the corresponding local declarations in the module where they occur. In addition, they are available in every module where they are imported.

Exporting Initializations

The exported initialization directive does not have any effect in the exporting module, but only in the module where it is imported. The initialization goal is called once in the context of every importing module.

Further Hints

All the export (and reexport) directives 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.

Exporting the same item twice, or exporting something that has previously been declared local, is accepted silently.

The following primitives implicitly export items: The module/3 directive and the create_module/3 predicate export the list of items given in their second argument. The tool/2 declaration implicitly exports the tool body predicate. Event handlers, error handlers and interrupt handlers are implicitly exported by the corresponding set_xxx_handler primitive.

The export/1 primitive can not only occur as a directive but can also be called at runtime.

Modes and Determinism


This predicate is sensitive to its module context (tool predicate, see @/2).


(4) instantiation fault
SpecList is not instantiated.
(5) type error
SpecList contains an invalid specification.
(94) trying to redefine an existing imported procedure
SpecList is already imported.


% A module that exports a predicate and an operator:

    :- module(m1).

    :- export
	op(700, xfx, before).

    A before B :-
    	A < B.

% Using this module elsewhere:

    :- module(m2).

    :- import m1.    % or :- use_module(".../m1...").

    main :-
    	3 before 7.  % operator and procedure definition are visible!

% Using before/2 without import, via explicit qualification:
% We can call before/2, but we cannot use the infix syntax!

    :- module(m3).

    main :-

% Error cases:

  :- export Q.                         (Error 4).
  :- export p/a.                       (Error 5).
  :- import p/1 from m.
  :- export p/1.                       (Error 94).

See Also

import / 1, reexport / 1, local / 1, use_module / 1, module / 1, : / 2, get_module_info / 3, document : icompile / 1, document : icompile / 2, domain / 1, macro / 3, op / 3, portray / 3, struct / 1