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

import +SpecList from +Module

Declares the procedure(s) specified by SpecList to be imported from the module Module.

+SpecList
Sequence of expressions of the form Atom/Integer.
+Module
Atom.

Description

There are three visibility levels which impose different restrictions on accessing a procedure.

local visible only in its home module.

exported visible in all modules that explicitly import it.

global visible in all modules that explicitly import it and in all modules where there is no procedure with the same name imported, declared or defined.

When looking for a procedure, it looks first for a procedure defined or declared in the caller module then for an imported one and if none exists, for a global one defined in another module.

import SpecList from Module declares the procedure(s) specified by SpecList to be imported from Module. If a procedure with the same name is already defined in Module and if it is already global or exported, that procedure is now visible. Otherwise, the procedure is not visible (yet).

Calling an imported procedure before it is actually defined as exported (or global) causes error 68 (calling an undefined procedure) even if a global procedure is defined in another module. This will be until either the import link is abolished (using abolish/1) either an exported (or global) predicate is defined in Module.

A procedure may be imported before it is actually defined and before the module Module exists.

If a procedure with the same name already exists in the caller module or if a procedure with the same name is already imported, an exception is raised. The exception is a warning if the procedure is imported twice from the same module. If the overwrite is wanted, the previous definition (or the import link) can be removed using abolish/1.

Importing a procedure will create new visibility links. This may produce exceptions it there is 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).

Fail Conditions

None.

Resatisfiable

No.

Exceptions

(4) Instantiation fault
Either SpecList or Module is not instantiated.
(5) Type error
SpecList is instantiated, but not to a sequence of expressions of the form Atom/Integer.
(5) Type error
Module is instantiated, but not to an atom.
(62)
importing SpecList would create a type conflict
(92)
SpecList is already local in caller module.
(93)
SpecList is already exported in caller module.
(94)
SpecList is already imported from another module than Module.
(95)
SpecList is already global in caller module.
(96)
SpecList is already imported from Module.

Examples


Success:

  [eclipse]: [user].
   :- export p/0.
   p :- writeln(hello).
   user   compiled 60 bytes in 0.00 seconds
  yes.
  [eclipse]: module(m).
  [m]: p.
  calling an undefined procedure p in module m
  [m]: import p/0 from eclipse.
  yes.
  [m]: p.
  hello
  yes.

Error:

  import P from m.                       (Error 4).
  import p/a from m.                     (Error 5).

  [eclipse]: [user].
   :- export t/0.
   :- tool(t/0, writeln/1).
   user   compiled 0 bytes in 0.00 seconds
  yes.
  [eclipse]: module(m).
  [m]: [user].
   % :- tool(t/0) here would prevent error 62 below
   p :- t.
   :- import t/0 from eclipse.             (Error 62).

  local p/0, (import p/0 from m).        (Error 92).
  export p/0, (import p/0 from m).       (Error 93).
  (import p/0 from m1),
      (import p/0 from m2).              (Error 94).
  global p/0, (import p/0 from m).       (Error 95).
  (import p/0 from m),
      (import p/0 from m).               (Error 96). (warning)


See Also

abolish / 1, export / 1, global / 1, import / 1, local / 1