[英]current_predicate in SICStus Prolog
SICStus Prolog offers both current_predicate/1 and current_predicate/2. SICStus Prolog 同时提供 current_predicate/1 和 current_predicate/2。
The manual page states: 手册页指出:
current_predicate(?PredSpec)
current_predicate(?PredSpec)
Unifies PredSpec with a predicate specifications of the form Name/Arity.
将 PredSpec 与 Name/Arity 形式的谓词规范统一起来。
current_predicate(?Name, ?Term)
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.
将 Name 与用户定义的谓词的名称统一,将 Term 与该谓词对应的最通用术语统一。
They appear to have the same features: both predicates work for enumerating predicates, both work with modules.它们似乎具有相同的功能:两个谓词都用于枚举谓词,都适用于模块。
The manual page comments:手册页评论:
current_predicate/1 is part of the ISO Prolog standard;
current_predicate/1 是 ISO Prolog 标准的一部分; current_predicate/2 is not.
current_predicate/2 不是。
Should I ever use current_predicate/2
in new (= non-legacy) code?我应该在新(=非旧版)代码中使用
current_predicate/2
吗?
Short answer, no.简短的回答,不。 Don't use it in new code.
不要在新代码中使用它。
The benefit of current_predicate/2
was to allow querying, using a predicate call template , if the predicate is defined, unlike current_predicate/1
. current_predicate/2
的好处是允许使用谓词调用模板进行查询,如果谓词已定义,这与current_predicate/1
不同。 Eg例如
...,
( current_predicate(_, foo(_, _)) ->
foo(A, B)
; ...
),
...
But you can often use instead the standard predicate_property/2
predicate, which takes a template as first argument.但是您通常可以使用标准的
predicate_property/2
谓词,它将模板作为第一个参数。
PS The Logtalk linter will scream at you (and suggest a more standard alternative) if it finds you calling current_predicate/2
:-) PS 如果 Logtalk linter 发现您调用
current_predicate/2
,它将对您大喊大叫(并建议一个更标准的替代方案 :-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.