[ ECLiPSe Module built-in.|Group Index| Full Index]

import +Module

Declare all the exported procedure of Module as being imported by default to the caller module.

+Module
Atom.

Description

Used to import by default all the exported procedures from the module Module to the caller module.

The purpose is to let the system import predicates from a given module when these predicates are not visible otherwise (i.e. when these predicates are not already defined or explicitly declared (using local/1, export/1, global/1 or import_from/2) in the caller module).

Therefore, when a predicate is already defined, declared or (explicitely) imported in the caller module, this predicate is not overwritten by the exported predicate with the same name defined in Module. No exceptions are raised in this case. Vice versa, when an exported predicate is defined in an imported module, it will be overwritten when a predicate of the same name is defined, declared or (explicitely) imported in the caller module.

However, when there is a name clash between two imported modules, a warning is raised (error 99) and (if the error handler succeeds) the instance of the procedure defined in the latest imported module becomes the visible one. Note that the warning can be prevented by explicitly importing the predicate using import_from/2).

Importing a module will create new visibility links. This may produce exceptions if there are type conflicts (e.g. importing a tool when a call has already been compiled to it as a non tool). Such type conflicts can be prevented using the declaration predicates (tool/1, external/1 or b_external/1).

When an error (or a warning that fails or exit_blocks) occurs, none of the predicates in Module are imported.

Fail Conditions

None.

Resatisfiable

No.

Exceptions

(4) Instantiation fault
Module is not instantiated.
(5) Type error
Module is instantiated, but not to an atom.
(62)
importing the predicates in Module would create a type conflict.
(80)
Module is not a module. Error 99 --- there is a name clash with an exported predicate of Module and an exported predicate of another imported module.

Examples


Success:
     [eclipse]: module(lib1).
     [lib1]: [user].
      :- export a/1, b/1, c/1, d/1.
      a(lib1).
      b(lib1).
      c(lib1).
      d(lib1).
      user        compiled 160 bytes in 0.02 seconds
     yes.
     [lib1]: module(lib2).
     [lib2]: [user].
      :- export a/1, b2/1, c/1.
      a(lib2).
      b2(lib2).
      c(lib2).
      user        compiled 120 bytes in 0.00 seconds
     yes.
     [lib2]: module(eclipse).
     [eclipse]: [user].
      :- import c/1 from lib1.
      d(eclipse).
      user        compiled 40 bytes in 0.00 seconds
     yes.
     [eclipse]: import lib1.
     yes.
     [eclipse]: import lib2. % only one warning for a/1.
     warning: name clash with other imported module(s)
  in import lib2
     yes.
     [eclipse]: a(A), b(B), b2(B2), c(C), d(D).
     A = lib2   % name clash: second imported is used
     B = lib1   % imported from lib1
     B2 = lib2  % imported from lib2
     C = lib1   % explicitely imported: no warning !
     D = eclipse  % defined in caller module: not overwritten !
     yes.

Error:
     import L.                   (Error 4).
     import 1.                   (Error 5).

     [eclipse]: [user].
      % :- tool(t/0) here would prevent error 62 below
      p :- t. % call compiled before tool declaration
      user        compiled 32 bytes in 0.00 seconds
     yes.
     [eclipse]: module(lib).
     [lib]: [user].
      :- tool(t/0, t/1).
      :- export t/0.
      user        compiled 0 bytes in 0.02 seconds
     yes.
     [lib]: module(eclipse).
     [eclipse]: import lib.        (Error 62).

     import no_module.           (Error 80).

     [eclipse]: module(lib1).
     [lib1]: export p/0.
     yes.
     [lib1]: module(lib2).
     [lib2]: export p/0.
     yes.
     [lib2]: module(eclipse).
     [eclipse]: import lib1.
     yes.
     [eclipse]: import lib2.       (Error 99). (warning)


See Also

abolish / 1, export / 1, global / 1, import_from / 2, local / 1