I’m using: SWI-Prolog version 7.6.4 and 8.0.2
Basically, I want the code to model knowledge bases for many agents. There is a common set of predicates that all the agents use, and each agent has its own percept info.
Approach taken:
Each agent stores their own data (e.g., perception) in their own module. For example, agt23:percept/1
All agents share static predicates for reasoning; those predicates are in a module called, say, kb
, which exports many predicates. All agents will use that module kb
, by using agtXX:use_module(kb)
. So, modules agtXX
will have access to all predicates in module kb
.
However, many predicates in kb
make use of predicates defined in the specific calling agent module. For example, they use percept/1
. For example, in module kb
I have:
location(X) :-
percept(P),
extract_location(X,P).
Now, because location(X)
is in module kb
, it tries to find percept/1
in kb
and not in the module that called location/1
.
My only solution was to use:
:- module_transparent(location/1).
location(X) :-
context_module(M),
M:percept(P),
extract_location(X,P).
This works but it is a lot of work as many many predicates in kb
are meant to have goals against the calling module. The alternative is just to not use modules and have one huge database with all predicates, and duplicate them in every agent module.
Is there a best way to do this? Am I missing something on modules here?
Thanks a lot to whoever can give me a hint!
Sebastian