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

local +SpecList

Declares the procedure(s) and other modular items specified by SpecList to be local to the caller module. If a global procedure of the same name is defined in another module it is made invisible.

+SpecList
Sequence of modular item specifications.

Description

This predicate is used to declare the visiblity of predicates and other names as local. SpecList is a comma-separated list of expressions of the following form:

Name/Arity predicate specification

variable(Name) non-logical variable specification

reference(Name) reference specification

array(Name) untyped non-logical array specification

array(Name,Type) typed non-logical array specification

record(Name) record key specification

struct(Prototype) structure declaration

op(Prec,Assoc,Name) operator specification

For predicates, 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.

local +SpecList declares the procedure(s) specified by SpecList local and therefore not accessible outside of its home module. A procedure can be declared as local before it is actually defined. Since local is the default visibility, the main purpose of this is to allow redefinitions that would otherwise cause name clashes or type conflicts.

If a procedure that was exported or global and imported by other modules is made local, all the import links are updated.

If a procedure with the same name was already imported from another module, an error is raised. Import links must be cut explicitely using abolish/1.

Fail Conditions

None.

Resatisfiable

No.

Exceptions

(4) Instantiation fault
SpecList is not instantiated.
(5) Type error
SpecList is instantiated, but not to a sequence of expressions of the form Atom/Integer.
(87)
SpecList is already local.
(94)
SpecList is already imported.

Examples


Success:

  % hide a global predicate with a local one
  [eclipse]: [user].
   :- global p/1.
   p(eclipse).
   user compiled 40 bytes in 0.00 seconds
  yes.
  [eclipse]: module(m).
  [m]: [user].
   :- local p/1. % can be omitted here since default is local.
   p(m).
   user compiled 40 bytes in 0.00 seconds
  yes.
  [m]: p(X).
  X = m
  yes.
  [m]: abolish(p/1). % local predicate is abolished
  yes.
  [m]: p(X).         % global is visible again
  X = eclipse
  yes.

  % prevent warnings when redefining a built-in:
  [eclipse]: [user].
   :- local name/2. % prevent warnings when compiling name/2
   name(a,b).
   user compiled 52 bytes in 0.00 seconds
  yes.
  [eclipse]: name(X, Y).
  X = a
  Y = b
  yes.

Error:

  local P.                           (Error 4).
  local p/a.                         (Error 5).
  local(p/0), local(p/0).            (Error 87). (warning)
  (import p/0 from m), local(p/0)    (Error 94).


See Also

abolish / 1, export / 1, global / 1, import / 1, import_from / 2, op / 3, variable / 1, reference / 1, array / 1, array / 2, record / 1, struct / 1