【发布时间】:2021-11-24 19:30:06
【问题描述】:
prolog 应该是找到五个 statements 语句的顺序。一切正常,但是当我调用查询 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])
完整的 Prolog 程序:
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])
【问题讨论】:
-
沙盒,我拿表明你正在使用 SWISH。我不是 SWISH 用户,所以无法帮助您。尝试安装 SWI-Prolog 并从命令行执行。我怀疑是
call/1导致了这个问题,但这纯粹是猜测。再一次没有告诉鸭子。
标签: prolog swi-prolog swi-prolog-for-sharing