我写了这个小程序:
married(guy1, fem1).
married(guy2, fem2).
married_to(X,Y):-!, married(X,Y); married(Y,X).
印刷:
X = guy1,
Y = fem1 ;
X = guy2,
Y = fem2.
我的目的是打印已婚夫妇,但每人打印一次。上面的规则对我有用,但我不明白为什么!这是如何运作的?
这有什么区别:
married_to(X,Y):- married(X,Y); married(Y,X).
这打印:
X = guy1,
Y = fem1 ;
X = guy2,
Y = fem2 ;
X = fem1,
Y = guy1 ;
X = fem2,
Y = guy2.