I'm trying to write a predicate move/3
which handles several kinds of terms, each kind of which is defined in a separate file. I'm trying to use modules for this, because the files contain other predicates which should be namespaced appropriately.
So, I've created a module cat.prolog
with contents:
:- module(cat, [move/3]).
:- multifile(move/3).
move(cat(C), P, cat(C2)) :-
...
Similarly for dog.prolog
.
And main.prolog
with:
:- use_module(['cat.prolog'], [move/3]).
:- use_module(['dog.prolog'], [move/3]).
(various predicates that use move/3 and expecting the clauses from all imported modules to be applicable.)
Trying to run this in SWI-Prolog:
?- ['main.prolog'].
% cat.prolog compiled into cat 0.00 sec, 4,800 bytes
ERROR: Cannot import dog:move/3 into module user: already imported from cat
Warning: /home/edmund/main.prolog:2:
Goal (directive) failed: user:use_module([dog.prolog],[move/3])
% main.prolog compiled 0.00 sec, 10,176 bytes
true.
At this point I can use dog:move/3
and cat:move/3
but not move/3
. It works for the cat
case but not the dog
case.
I get the feeling there's a really obvious way to do this. I've tried combining modules and imports and multifile directives in many ways and still not found it yet...
main
module as well? – Shon