gpt4 book ai didi

prolog - SICStus Prolog 中的 current_predicate

转载 作者:行者123 更新时间:2023-12-04 10:01:08 24 4
gpt4 key购买 nike

SICStus Prolog 提供 current_predicate/1 和 current_predicate/2。

manual page状态:

current_predicate(?PredSpec)

Unifies PredSpec with a predicate specifications of the form Name/Arity.

current_predicate(?Name, ?Term)

Unifies Name with the name of a user-defined predicate, and Term with the most general term corresponding to that predicate.

它们似乎具有相同的特征:两个谓词都用于枚举谓词,都与模块一起工作。

手册页注释:

current_predicate/1 is part of the ISO Prolog standard; current_predicate/2 is not.

我应该在新的(= 非遗留的)代码中使用 current_predicate/2 吗?

最佳答案

简短的回答,没有。不要在新代码中使用它。

current_predicate/2 的好处是允许查询,使用谓词调用模板,如果定义了谓词,不像current_predicate/1。例如

...,
( current_predicate(_, foo(_, _)) ->
foo(A, B)
; ...
),
...

但您通常可以改用标准的 predicate_property/2 谓词,它将模板作为第一个参数。

附言如果 Logtalk linter 发现你在调用 current_predicate/2 :-)

,它会向你尖叫(并建议一个更标准的替代方案)

关于prolog - SICStus Prolog 中的 current_predicate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61814299/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com