A note on usage of multifile/1, since I got tripped up, and it might help others.
When predicates that are declared to be multifile/1 are added from other modules, they need to be prefixed with the module into which the declaration will be made.
E.g., if we define the multifile predicate bar/1
in foo.pl
:
:- module(foo, [bar/1]). :- multifile bar/1.
then to add new clauses for the predicate in baz.pl
, we prefix the clause's head with the originating module foo
, like so:
:- module(baz, []). :- use_module(foo). foo:bar(1). foo:bar(2).
The effect is to add these clauses into module foo
. If we had instead tried just adding the facts as bar(1)
, we would have hit the warning:
Local definition of baz:bar/1 overrides weak import from foo
because we'd have overwritten foo:bar/1
with the newly defined baz:bar/1
.
For more discussion you can see https://swi-prolog.discourse.group/t/having-trouble-using-multifile-1-for-multi-file-predicates/4460