prologswi-prologprolog-directive-dynamic

current_predicate/1 does not work with :- dynamic?


I have some predicates that I define using asserts in Prolog.

I am using current_predicate/1 in order to know whether the assert has been run or not (only one value needs to be asserted).

However, swipl keeps complaining:

Warning: The predicates below are not defined. If these are defined
Warning: at runtime using assert/1, use :- dynamic Name/Arity.
Warning: 
Warning: amountOfStudentsInCourseAsserted/2, which is referenced by

So, I added the :- dynamic amountOfStudentsInCourseAsserted/2, but unfortunately, this adds the predicate to the current_predicate(Predicate).. Therefore I cannot use current_predicate/1 anymore if I am using this dynamic naming.

Is there another predicate like current_predicate/1that isn't true for dynamic names?


Solution

  • You can use in alternative the predicate_property/2 built-in predicate and the number_of_clauses/1 property.