I’m using: SWI-Prolog version 8.0.2
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
I want the code to:
retract asserted facts.
i’ve tested predicates defined with both the dynamic and thread_local definitions ( same results )
i’ve tested both retractall on a compound built with PL_put_variable (i.e. retractall(functor(,,…)
-> next_solution returns PL_S_TRUE but does not retract ( subsequent “selection” of the data returns data ).
i’ve tried implementing my own retractall ( i.e. read all values/solutions and explicitly retract each one )
but next_solution on the retract returns PS_S_FALSE. ( and does not retract the data ).
code examples :
using retractall :
const predicate_t RetractCMD = PL_predicate(“retractall”, 1, “database”);
const functor_t Targetfunctor = PL_new_functor(PL_new_atom(“target”), 4);
term_t EmptyTargetParameters = PL_new_term_refs(4);
if ( PL_put_variable(EmptyTargetParameters) != PL_S_TRUE
|| PL_put_variable(EmptyTargetParameters+1) != PL_S_TRUE
|| PL_put_variable(EmptyTargetParameters+2) != PL_S_TRUE
|| PL_put_variable(EmptyTargetParameters+3) != PL_S_TRUE)
{ exit }
term_t TargetCompoundToRetract = PL_new_term_ref();
if (PL_cons_functor_v(TargetCompoundToRetract,Targetfunctor,EmptyTargetParameters) != PL_S_TRUE)
{ exit }
const qid_t RetractTargetsQID = PL_open_query(NULL, PL_Q_NODEBUG ,RetractCMD,TargetCompoundToRetract);
if (RetractTargetsQID == 0)
{ exit }
QueryRc = PL_next_solution(RetractTargetsQID);
if (QueryRc != PL_S_TRUE)
{ exit }
using retract :
const predicate_t PredToDelete = PL_predicate(“target”, 4, “database”);
term_t DataToDelete = PL_new_term_refs(4);
const functor_t functorToDelete = PL_new_functor(PL_new_atom(“target”), 4);
const predicate_t RetractCMD = PL_predicate(“retract”, 1, “database”);
const qid_t GetDataQID = PL_open_query(NULL,PL_Q_NODEBUG,PredToDelete,DataToDelete);
if (GetDataQID == 0)
{ exit }
int QueryRc = PL_next_solution(GetDataQID);
while (QueryRc != PL_S_FALSE)
{
// construct compound argument for retract command
term_t CompoundToRetract = PL_new_term_ref();
if (PL_cons_functor_v(CompoundToRetract,functorToDelete,DataToDelete) != PL_S_TRUE)
{ exit }
const qid_t RetractQID =
PL_open_query(NULL,PL_Q_NODEBUG,RetractCMD,CompoundToRetract);
if (RetractQID == 0)
{ exit }
//
QueryRc = PL_next_solution(RetractQID);
if (QueryRc != PL_S_TRUE)
{ exit }
}