current_predicate/1 不适用于 :- 动态?

current_predicate/1 does not work with :- dynamic?

我在 Prolog 中使用断言定义了一些谓词。

我正在使用 current_predicate/1 以了解断言是否为 运行(只需要断言一个值)。

然而,swipl一直在抱怨:

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

所以,我添加了 :- dynamic amountOfStudentsInCourseAsserted/2,但不幸的是,这将谓词添加到 current_predicate(Predicate).. 因此,如果我正在使用它,我就不能再使用 current_predicate/1动态命名。

有没有像 current_predicate/1 这样的谓词不适用于动态名称?

您可以替代使用 predicate_property/2 内置谓词和 number_of_clauses/1 属性.

:- dynamic 声明是合适的,因为它将使符号在数据库中已知。然后在断言之前尝试匹配(使用适当的参数,在以下示例中忽略):

...
(  amountOfStudentsInCourseAsserted(_,_)
-> true
;  assert(amountOfStudentsInCourseAsserted(X,Y))
),
...