I am trying to further my understanding of Prolog, and how it handles list unification. So I am stuck with this example, that I know the answer as I execute the code, but I cannot understand how it works.
[X,a,X,f(X,a)|Y] = [Z,Z|Y]
The answer is:
X=Z
Z=a
Y=_
L=[a,f(a,a)|Y]
I know that the head unifies with the other head, so if I make some changes, like these:
let C=[X,a,X,f(X,a)]
let D=[Z,Z]
and the unification should go this way:
[C|Y]=[D|L]
so Y must be equal to L, not _, right? Can someone explain me this better and correct my mistake?
X=Z, Z=a, Y = [a,f(a,a)|Y]
which I guess is the result you expected. – hynner