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