I fail to understand swi-prolog's behavior when the database
on(a,b).
is queried with
:- on(A,B),on(C,D).
To my best understanding, what is supposed to happen is the following: first, the leftmost goal in the query is matched against the database. This succeeds immediately, leading to the removal of said goal from the query as well as to the substitution
[A=a,B=b]
Next, this substitution is applied to the remaining goal, which does nothing, since neither A nor B appear in the second goal. Now, the remaining goal is matched against the database, which again succeeds. Now we are done, and we should be left with the substitution
[A=a,B=b,C=a,D=b]
And this should be the only substitution the interpreter is able to come up with, provided my understanding of prologs procedural semantics is correct. Unfortunately, swi-prolog thinks otherwise. Instead it comes up with the substitution
[A=C,B=D,C=a,D=b]
If you are very generous, you could say that "both answers mean the same", but I am never generous when it comes to understanding what a program does, and I ran into this in a context where it actually matters. So I would be most appreciative if someone could help me to figure out what's going on.
