1
比方說,我有3名兒童雙胞胎Prolog中會重複答案
person(pet,fox,date(5,may,2004),unemployed).
person(jim,fox,date(5,may,2004),unemployed).
person(george,fox,date(9,december,2002),unemployed).
child(X):-X=person(pet,fox,date(5,may,2004),unemployed).
child(X):-X=person(jim,fox,date(5,may,2004),unemployed).
child(X):-X=person(george,fox,date(9,december,2002),unemployed).
我想這些兒童
twins(Child1,Child2) :-
child(Child1),child(Child2),
Child1=person(Fname1,_,Date1,_),
Child2=person(Fname2,_,Date2,_),
Fname1\=Fname2,
Date1=Date2.
問題是,當我問序言雙胞胎的雙胞胎(X, Y)。我會再次得到一些答案。如何防止呢?
?- twins(X,Y).
X = person(pet, fox, date(5, may, 2004), unemployed),
Y = person(jim, fox, date(5, may, 2004), unemployed) ;
X = person(jim, fox, date(5, may, 2004), unemployed),
Y = person(pet, fox, date(5, may, 2004), unemployed) ;
false.