【问题标题】:current_predicate in SICStus PrologSICStus Prolog 中的 current_predicate
【发布时间】:2020-05-15 07:48:46
【问题描述】:

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

manual page 声明:

current_predicate(?PredSpec)

将 PredSpec 与 Name/Arity 形式的谓词规范统一起来。

current_predicate(?Name, ?Term)

将 Name 与用户定义的谓词的名称统一,将 Term 与该谓词对应的最通用术语统一。

它们似乎具有相同的功能: 两个谓词都用于枚举谓词,都适用于模块。

手册页cmets:

current_predicate/1 是 ISO Prolog 标准的一部分; current_predicate/2 不是。

我应该在新(= 非旧版)代码中使用 current_predicate/2 吗?

【问题讨论】:

    标签: prolog iso-prolog sicstus-prolog


    【解决方案1】:

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

    current_predicate/2 的好处是允许使用谓词调用模板 进行查询,前提是定义了谓词,这与current_predicate/1 不同。例如

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

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

    附:如果 Logtalk linter 发现你打电话给 current_predicate/2 时,它会向你尖叫(并建议一个更标准的替代方案):-)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多