I am new to Prolog and I'm struggling with the following problem using SWI-Prolog.
I have several files dataBase1.pl
, dataBase2.pl
, ... with the same structure
(based on this thread)
:- module(dataBase1,[]).
:- use_module(library(persistency)).
:- persistent
predicate1(A:any, B:any),
predicate2(A:any, B:any).
:- initialization(init).
init :-
absolute_file_name('dataBase1.db', File, [access(write)]),
db_attach(File, []).
predicate1/2, predicate2/2
are common to all the database files.
Then, I defined in a third file predicates.pl
several clauses which make use of clauses in the previous databases such as testPredicate(A,B) :- predicate1(A,B), predicate2(A,B).
My problem is that I would like above clause to use predicate1/2, predicate2/2
from all the modules corresponding to database files.
In the current state, I need to precise the context module in order to use
predicate1/2, predicate2/2
(ie dataBase1:predicate1/2, dataBase2:predicate1/2,...
.)
I can't use use_module/1
as I will add/remove database file dynamically.
Thanks in advance for any advice !
Edit : Following the discussion in the comments, how can I define query-able predicate of the form head(X,Y) :- body()
as persistent dynamic predicate ?
[ISO]dynamic :PredicateIndicator, ... Informs the interpreter that the definition of the predicate(s) may change during execution (using assert/1 and/or retract/1). In the multithreaded version, the clauses of dynamic predicates are shared between the threads.
In Prolog, you always have a Horn clause, which has a head and a body. The head is what goes before the :- and names the predicate. The body is the list of expressions to the right of the :- . You should read this as "infer min(X, Y, Min) when X =< Y and Min = X , or else Min = Y ".
SWI-Prolog -- (discontiguous)/1. Informs the system that the clauses of the specified predicate(s) might not be together in the source file.
Goals relating to user-defined predicates are evaluated by examining the database of rules and facts loaded by the user. Prolog attempts to satisfy a goal by matching it with the heads of clauses in the database, working from top to bottom.
iirc, you should call predicates using module name as a prefix separated by colon.
http://www.swi-prolog.org/pldoc/man?section=overrule
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With