:-dynamic listofQuestions/2.
myrule:-
write('P = '), write(Percent), write('-'),write(X),
( listofQuestions(Percent,X) -> true ; assert(listofQuestions(Percent,X)) ),
The code snippet might not be required to answer my question.
I want to assert to a blank 'listofQuestions' everytime I call my rule. This only happens if I close my prolog window and restart it.
Any suggestions?
abolish/1
removes all clauses of a given predicate from the database. Hence, just add a call toabolish(PredName/Arity)
whenever you need to remove the information about this predicate. Beware that after abolishing the call to the dynamic predicate does not fail but reports an error.In SWI-Prolog,
abolish
works on static procedures, unless the prolog flagiso
is set to true. If you intend to remove only dynamic predicates, you should better tryretractall
. Observe that in this case removal does not lead to an error being reported but to a failure.