C # Prolog Interface Disconnected from File

I just made a connection with SWI Prolog and want to manipulate the facts. for example to delay and approve them.

I have a 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 works to validate as expected, but not to return. The fact is that I want to delete all the facts of the tables (they are dynamic) from the file before inserting them. PlQuery.PlCall("retractall(tablet/2)."); this request should delete the entire entry in the file. as well as how to remove a fact, for example tablet(4,newatomic) , but not delete other facts.

The resulting file after execution:

 :- dynamic tablet/2. tablet(4, newatomic). tablet(1, n1ewatomic). tablet(2, n2ewatomic). 
+5
source share
1 answer

Well, I don’t want to delete the question, because it has two upvotes. Perhaps this will be useful for someone.

So the logic was right.

Whenever we want to add something to the database, we write:

 assert(predicat(var1, var2, ... , varn)) 

Whenever we want to remove something from the database, we write:

 retract(predicat(var1, var2, ... , varn)) retractall(predicat(var1, var2, ... , varn)) 

If all members are equal, then it is removed from db (also it must be dynamic)

If we want to delete all the data, we need to specify its variable. So that...

 retract(predicat(_,_,...,_)) retractall(predicat(_,_,...,_)) 

will delete all data matching the query. And to save the data, we simply write the following:

 tell('database_file.txt'), %opening file for writing listing(ig_node), %writing told. %closing/saving file 
0
source

All Articles