Prolog 无法到达谓词

Prolog Can't get to the predicate

序言应该找到五个语句语句的顺序。一切正常,但是当我调用查询 solution([A, B, C, D, E]) 时,出现如下沙箱错误:

错误:

Sandbox restriction!
Could not derive which predicate may be called from
      call(C)
      all(schoolgirl,[A,B,C,D,E])
      solution([A,B,C,D,E])

完整序言程序:

all(_,[]).
all(Pred, [X|Xs]):-
    P =..[Pred,X],
    call(P),
    all(Pred,Xs).
distinct([]).
distinct([X|Xs]):- 
    not(member(X, Xs)), distinct(Xs).
x0r(A, B):- 
    A, not(B).
x0r(A, B):-
    not(A), B.

schoolgirl(betty).
schoolgirl(ethel).
schoolgirl(joan).
schoolgirl(kitty).
schoolgirl(mary).

betty(Snd,Trd):- 
    x0r(Snd=kitty, Trd=betty).
ethel(Fst, Snd):- 
    x0r(Fst=ethel, Snd=joan).
joan(Trd, Fith):- 
    x0r(Trd=joan, Fith=ethel).
kitty(Snd, Forth):- 
    x0r(Snd=kitty, Forth=mary).
mary(Forth, Fst):- 
    x0r(Forth=mary, Fst-betty).

solution([Fst, Snd, Trd, Forth, Fith]):-
    all(schoolgirl, [Fst,Snd, Trd, Forth, Fith]),
    distinct([Fst, Snd, Trd, Forth, Fith]),
    betty(Snd, Trd),
    ethel(Fst, Snd),
    joan(Trd, Fith),
    kitty(Snd, Forth),
    mary(Forth, Fst).

电话是

solution([A, B, C, D, E])

正如一位评论者所说,这似乎是使用 SWI-Prolog 基于浏览器的 SWISH 系统时的一个特殊限制 (https://swish.swi-prolog.org/)。它不希望您将 call/1 与它不太了解的术语一起使用。

幸运的是,您可以提供更多信息:您在以下上下文中使用 call/1

P =..[Pred,X],
call(P),

也就是说,调用谓词 Pred 时只有一个参数 X。有一个更直接的语法:

call(Pred, X)

这足以使错误消失,并使 SWISH 愿意 运行 您的程序。 (实际上,这种语法更通用一些,因为它只需要将一个 additional 参数添加到 Pred 中已有的参数,因此 call(f(a), b) 会调用目标 f(a, b).)

您的查询现在将因有点模糊的错误而终止:

procedure `A-B' does not exist
Reachable from:
      call(_1690-betty)
      not(A-betty)
      x0r(A=mary,B-betty)
      mary(A,B)
      solution(A)

您的 mary/2 谓词定义中有错字。