Take the 2-minute tour ×

I am learning Prolog for an university exam using SWI Prolog and I have some question about this simple program that implement the different predicate that say TRUE if two element are different (if they do not match) and say FALSE if they match.

This is the code:

different(X,X) :- !,


The problem is that if I try to execute the following query in the Prolog shell I always obtain FALSE:

[debug] 10 ?- different(a,b).

[debug] 11 ?- different(a,a).

As you can see the first query have to say TRUE because a don't match with b


share|improve this question
Why debug when stackoverflow? –  Boris Apr 9 '13 at 13:11
I apologize for my stupid question...I have spent all night at work at office and I was just a litle bit in mental confusion –  AndreaNobili Apr 9 '13 at 14:17

2 Answers 2

up vote 3 down vote accepted

change diferent(_,_) to different(_,_). Ie it is a spelling error. Your second predicate is not being examined as it does not match your query.

The program should be

different(X,X) :- !,fail.
share|improve this answer
OMG...I just came back from a whole night at work in office...evidently are not yet able to concentrate ....I need more coffee...tnx –  AndreaNobili Apr 9 '13 at 11:48

If you are using emacs for editing your prolog files (If not I strongly recommend you switching to it) I suggest you using hi-lock-mode. I will highlight in a pattern-like fashion all matches in the file whenever the cursor is over a word. It can save you hours of pain when you develop bigger projects.

enter image description here

share|improve this answer

Your Answer


