Prolog Question: Just started learning prolog and this was on one of the practice quizzes we were given.
Given:
avenger(thor).
avenger(captainAmerica).
sibling(thor,loki).
asgardian(thor).
asgardian(X) :- sibling(Y,X),asgardian(Y).
train1(X,Y) :- avenger(X),!,avenger(Y).
train2(X,Y) :- avenger(X),X\=Y,avenger(Y).
List all answers returned by the following queries.
train2(A, captainAmerica). %returns A=thor.
train2(captainAmerica, A). %returns false.
My question is about the second query. Why wouldn't this return A=thor. ? I messed around a bit and if i change train2 to
train2(X,Y) :- avenger(X),avenger(Y),X\=Y.
when i run the second query I get
A=thor.
A quick explanation of why the order of the rules in the query matters here would be awesome. Thanks.