Module 1
Matching without unification

 

 

Sometimes we require matching without unification. Prolog has a built-in predicate "==". This matches two terms as before but, to succeed, the two terms have to already have identical values.

Now for some examples. Obviously two identical atoms will match.
   

     | ?- munich == munich.

     yes
An atom and an uninstantiated variable will not match, and an atom and an instantiated variable will match only if the variable is instantiated to a value exactly the same as the atom:
   
     | ?- russia == Country.

     no
     | ?- Country = russia, Country == russia.

     Country = russia ?
What happens if both terms are uninstantiated variables? The key point is whether or not the variables are distinct:
   
     | ?- Variable1 == Variable2.

     no
If the two variables have been previously unified, then (although they may not be instantiated (ie have a value)), the expression will succeed.
   
     | ?- Variable1 = Variable2, Variable1 == Variable2.

     Variable2 = Variable1 ?
Take time to work through the Self-Test 6