【问题标题】:What is the arity of the following complex terms?以下复杂术语的元数是什么?
【发布时间】:2014-12-30 14:10:24
【问题描述】:

我了解这两个事实是使用复杂术语表达的,而复杂术语又以复杂术语作为论据。术语嵌套在三个级别的术语中。

vertical(line(point(X,Y), point(X,Z))).

horizontal(line(point(X,Y), point(Z,Y))).

这是否意味着整个复杂项的元数为 1,而其他复杂项是嵌套的?

【问题讨论】:

  • verticalhorizontal 的 Arity 为 1。line 的 Arity 为 2。point 的 Arity 为 2。

标签: prolog logic arity


【解决方案1】:

请注意,您所说的“复杂术语”在 Prolog 中通常称为 复合术语。您可以通过以下方式轻松检查 Prolog 术语的数量:

?- functor(vertical(line(point(X,Y), point(X,Z))), _, Arity).
Arity = 1.

如您所见,在这种特殊情况下,您的直觉是正确的!

SWI7 特定

由于您已将 SWI-Prolog 标记添加到您的问题中,因此知道在 SWI 7 中还有 compound_name_arity/3 可能有用,它适用于 arity 0 的复合术语。(在其他 Prologs 中,复合术语零元将是一个原子。)例如:

?- functor(f(), _, Arity).
ERROR: functor/3: Domain error: `compound_non_zero_arity' expected, found `f()'
?- compound_name_arity(f(), _, Arity).
Arity = 0.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-30
    • 2016-12-05
    • 2016-01-14
    • 1970-01-01
    • 1970-01-01
    • 2021-10-30
    • 2017-09-21
    • 2018-10-23
    相关资源
    最近更新 更多