I am having trouble trying to figure out in what order unification is done. I have the following query:
[X, like | Z] = [I, Y, Prolog, language].
This gives me the following result:
X = I,
Z = [Prolog, language],
Y = like.
However, what I was expecting is:
X = I,
Y = like,
Z = [Prolog, language].
Is there any specific order in which Prolog unifies terms?
EDIT:
I have a feeling that Prolog is giving higher priority to unification of an atom with a variable over that of a variable with an atom. Is that so?
There is no order. Here is the mapping that is performed:
if that mapping is possible (i.e. if the variables
I,Y,X,Zare bound to terms that allow unification to succeed)In this case, assuming that all variables are unbound, then:
Variables
IandXwill become "the same variable" (more clearly, the variable nameIandXwill designate the same empty storage cell)Variable
Ywill become the atomlike' (more clearly, the storage cell designated by variable nameYwill be set tolike`)Variable
Ztakes up the "rest (or suffix) of the list" (everything behind the|) and will become the complex term `[Prolog, language]'.Variable
Prologis not changed and stays what it was.