Prolog different variable, same value

177 Views Asked by At

If you query e.g.

?- X = 10, Y = 10, Z = 10.

The output is

X = Y, Y = Z, Z = 10.

But my X is totally different from Y, they just happen to accidentally both be 10, so it doesn't seem clear/logical to display it that way. Can i make it look like this instead?:

X = 10, Y = 10, Z = 10.
2

There are 2 best solutions below

2
3IA21_Yolenta Alfrida More On

change([H,Q,D,N,P]) :-member(H,[0,1,2]), /* Half-dollars /member(Q,[0,1,2,3,4]), / quarters /member(D,[0,1,2,3,4,5,6,7,8,9,10]) , / dimes /member(N,[0,1,2,3,4,5,6,7,8,9,10, / nickels /11,12,13,14,15,16,17,18,19,20]),S is 50H + 25Q +10D + 5*N,S =< 100,P is 100-S.

8
repeat On

I share your preference. Note that different Prolog systems have different top levels...

SWI-Prolog gives me this:

$ swipl
?- X = 10, Y = 10, Z = 10.
X = Y, Y = Z, Z = 10.

Traella Prolog says something quite similar:

$ tpl 
?- X = 10, Y = 10, Z = 10.
   X = 10, Y = X, Z = X.

GNU-Prolog and Scryer Prolog, however, give me answers that I like better:

$ gprolog
| ?- X = 10, Y = 10, Z = 10.

X = 10
Y = 10
Z = 10

yes

$ scryer-prolog 
?- X = 10, Y = 10, Z = 10.
   X = 10, Y = 10, Z = 10.