The imported predicates act as weak symbols in the module
into which they are imported. This implies that a local definition of a
predicate overrides (clobbers) the imported definition. If the flag
warn_override_implicit_import
is true
(default), a warning is printed. Below is an
example of a module that uses library(lists), but redefines flatten/2,
giving it a totally different meaning:
:- module(shapes, []). :- use_module(library(lists)). flatten(cube, square). flatten(ball, circle).
Loading the above file prints the following message:
Warning: /home/janw/Bugs/Import/t.pl:5: Local definition of shapes:flatten/2 overrides weak import from lists
This warning can be avoided by (1) using use_module/2
to only import the predicates from the lists
library that
are actually used in the‘shapes' module, (2) using the except([flatten/2])
option of use_module/2,
(3) use
:- abolish(flatten/2).
before the local definition or (4) setting
warn_override_implicit_import
to false
. Globally disabling this warning is only
recommended if overriding imported predicates is common as a result of
design choices or the program is ported from a system that silently
overrides imported predicates.
Note that it is always an error to import two modules with use_module/1 that export the same predicate. Such conflicts must be resolved with use_module/2 as described above.