Prolog奇怪的统一

时间:2016-08-12 15:50:16

标签: prolog unification

我有以下程序:

%% adjacent((Xs, Ys), (Xa, Ya)) - <Xa, Ya> is adjacent to <Xs, Ys>.
adjacent((Xs, Ys), (Right, Ys)) :- Right is Xs + 1.
adjacent((Xs, Ys), (Left, Ys)) :- Left is Xs - 1.
adjacent((Xs, Ys), (Xs, Up)) :- Up is Ys + 1.
adjacent((Xs, Ys), (Xs, Down)) :- Down is Ys - 1.

当我做

?- adjacent((5, 6), (X, Y)).

它给了我

X = Y, Y = 6 ;
X = 4,
Y = 6 ;
X = 5,
Y = 7 ;
X = Y, Y = 5.

发生了什么?

1 个答案:

答案 0 :(得分:0)

好吧,我知道我很蠢。 SWI-Prolog只是汇总变量&#39;输出的值,当两者都相同时......