3

我有一些使用 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

因此,我添加了,但不幸的是,这会将谓词添加到 current_predicate(Predicate).. 因此,如果我使用此动态命名,:- dynamic amountOfStudentsInCourseAsserted/2我将无法再使用。current_predicate/1

对于动态名称,是否还有另一个这样的谓词current_predicate/1不正确?

4

2 回答 2

1

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

...
(  amountOfStudentsInCourseAsserted(_,_)
-> true
;  assert(amountOfStudentsInCourseAsserted(X,Y))
),
...
于 2015-12-28T08:19:12.160 回答
1

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

于 2015-12-27T23:40:12.087 回答