I just established a connection to SWI Prolog and want to manipulate facts. e.g. retract and assert them.
I have some function like this:
String[] param = { "-q" };
PlEngine.Initialize(param);
PlQuery.PlCall("consult('tablets.pl').");
PlQuery.PlCall("assert(tablet(4,newatomic)).");
PlQuery.PlCall("tell('tablets.pl'), listing(tablet/2), told.");
PlQuery.PlCall("retractall(tablet/2).");
PlQuery.PlCall("assert(tablet(1,n1ewatomic)).");
PlQuery.PlCall("assert(tablet(2,n2ewatomic)).");
PlQuery.PlCall("tell('tablets.pl'), listing(tablet/2), told.");
As you can see this function, it's working for assertion as expected, but not for retract. The matter is that, I want to delete all tablets facts (they are dynamic) from file before inserting the next ones. PlQuery.PlCall("retractall(tablet/2).");
this query must delete all record that are in the file. and also how to delete a fact for example tablet(4,newatomic)
, but not to delete another facts.
The resulting file after execution is:
:- dynamic tablet/2.
tablet(4, newatomic).
tablet(1, n1ewatomic).
tablet(2, n2ewatomic).