foo(X) :-
bar(X) \= baz(X).
?- bar(2).
yes
?- baz(2).
yes
?- foo(2).
yes
Why does foo(2) output yes? If we query yes \= yes we get a no.
foo(X) :-
bar(X) \= baz(X).
?- bar(2).
yes
?- baz(2).
yes
?- foo(2).
yes
Why does foo(2) output yes? If we query yes \= yes we get a no.
foo(2) outputs yes because \=/2 succeeds when it cannot unify the left argument with the right argument.
The left argument is bar(2) and the right one is baz(2) so they will not unify as the principal functor of each term is diffent (bar vs baz). It doesn't matter the the argument (2) is the same for both terms.
With bar(X) \= bar(X) we also get a no. But baz is not bar.
In Prolog, there is no "evaluation" of terms. Terms are terms.
bar(X) we get X=2 back (evidently).bar(2) we get a yes back.1 \= 2 we get a yes back.bar \= baz we get a yes back.Same if we call bar(1) \= baz(2) or bar(2) \= baz(2) or bar(X) \= baz(X).
The \= predicate means "can't be unified". yes can be unified with yes, but bar(2) can not be unified with baz(2). Same with X instead of 2.
The \= is the predicate being called here, and both bar(X) and baz(X) are its arguments -- which are symbolic terms.
There is no automatic "evaluation" of terms in Prolog.