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

global +SpecList

Declares the procedure(s) and other modular items specified by SpecList to be global.

+SpecList
Sequence of modular item specifications.

Description

This predicate is used to declare the visiblity of predicates and other names as global. 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.

global +SpecList declares the procedure(s) specified by SpecList global and hence visible to all modules where no procedure with the same functor has been declared or defined and to all module where it is explicitely imported (using import_from/2 or import/1).

A procedure can be declared global before it is actualy defined.

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.

Only one global procedure of a certain name can exist at any time. Declaring a procedure as global when there is already a global procedure of the same name will raise a warning if the procedure is already global in the caller module but will raise an error if a global procedure with the same name exists in another module.

Declaring a procedure as global will make it visible to other modules. This may produce exceptions it there are type conflicts (e.g. when declaring a tool as global when it is visible from a module where 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
SpecList is not instantiated.
(5) Type error
SpecList is instantiated, but not to a sequence of expressions of the form Atom/Integer.
(62)
making SpecList global would create a type conflict
(89)
SpecList is already global in caller module.
(94)
SpecList is already imported.
(95)
SpecList is already global in another module.

Examples


Success:

  [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 omited 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).
  yes. % local predicate is abolished, global is visible again
  [m]: p(X).
  X = eclipse
  yes.

Error:

  global(Q).                        (Error 4).
  global("Pred").                   (Error 5).

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

  global(p/0), global(p/0).         (Error 89). (warning)
  (import p/0 from m), global(p/0). (Error 94).
  global(true/0).                   (Error 95).


See Also

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