title: Route planning in Prolog
body: <p>Here is a route planning program given by an online tutorial:-</p>
  
  <pre><code>route(X,Y,R) :-
   route(X,Y,[X],R).
  
  route(X,Y,_,[drive(X,Y)]) :-
   travel(X,Y).
  route(X,Y,V,[drive(X,Z)|R]) :-
   travel(X,Z),
   \+ member(Z,V),
   route(Z,Y,[Z|V],R)
   Z \= Y.     %Only required if Y is not ground.
  
  
  travel(X,Y) :- road(X,Y).
  travel(X,Y) :- road(Y,X). 
  
  
  road(arad,sibiu).
  road(arad,timisoara).
  road(arad,zerind).
  road(zerind,oradea).
  road(oradea,sibiu).
  road(sibiu,fagaras).
  </code></pre>
  
  <p>What I do not understand is the commented statement: <code>Z\=Y</code>.
  Why this statement is needed? And why that statement is only needed if <code>Y</code> is not ground?</p>