call/1 的 SWI Prolog 描述:"clauses may have variables as subclauses"?

SWI Prolog description of call/1: "clauses may have variables as subclauses"?

call/1 的描述说:

call(:Goal)

Invoke Goal as a goal. Note that clauses may have variables as subclauses, which is identical to call/1.

我不明白"clauses may have variables as subclauses"。

谁能举个例子?

正文转换(7.6.2 将术语转换为子句的正文)按照 ISO 核心标准要求,子句正文中直接位于控制结构内的变量是由 call/1 包裹。

这是一个例子:

?- [user].
and(X,Y) :- X,Y.
^D
?- listing.
and(X,Y) :- call(X), call(Y).

效果是调用 ! 无效,因为剪切被限制在 call/1 内。

这是在这里看到的:

?- [user].
p(a).
p(b).
?- p(X), !.
X = a
?- and(p(X),!).
X = a ;
X = b

编辑 2019 年 12 月 31 日:
Prolog 系统可能希望将 (*->)/2 (软切)添加到那些参数被转换的控制结构中,从而修改 7.6.2.


来自 ISO/IEC 13211-1: 1995 Prolog

7.6.2 Converting a term to the body of a clause

A term T can be converted to a goal G which is the body of a clause:

a)

If T is a variable then G is the control construct call (7.8.3), whose argument is T.

b)

If T is a term whose principal functor appears in table 9 then G is the corresponding control construct. If the principal functor of T is call/1 or catch/3 or throw/1 then the arguments of T and G are identical, else if the principal functor of T is (',')/2 or (;)/2 or (->)/2 then each argument of T shall also be converted to a goal.

c)

If T is an atom or compound term whose principal functor FT does not appear in table 9 then G is a predication whose predicate indicator is PT, and the arguments, if any, of T and G are identical.

7.8.3 call/1

call(G) is true iff G represents a goal which is true.

When G contains ! as a subgoal, the effect of ! shall not extend outside G.

Table 第 37 页的 9:主仿函数和控制结构

  • (',')/2 转换目标参数
  • (;)/2 转换目标参数
  • (->)/2 转换目标参数
  • !/0
  • call/1 目标参数未转换
  • true/0
  • fail/0
  • catch/3 目标参数未转换
  • throw/1