I have written this little program:
married(guy1, fem1).
married(guy2, fem2).
married_to(X,Y):-!, married(X,Y); married(Y,X).
Prints:
X = guy1,
Y = fem1 ;
X = guy2,
Y = fem2.
My purpose was to print the married couples but one time each. The above rule works for me, but I can't understand why! How does this work?
What's the difference with that:
married_to(X,Y):- married(X,Y); married(Y,X).
This prints:
X = guy1,
Y = fem1 ;
X = guy2,
Y = fem2 ;
X = fem1,
Y = guy1 ;
X = fem2,
Y = guy2.