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).
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).