title: Prolog - Finding adjacent elements in a list
body: <p>I'm trying to define a predicate <code>adjacent(X, Y, Zs)</code> that is true if X and Y are adjacent in a list. My code is currently this:</p>
  
  <pre><code>adjacent(_, _, []).
  adjacent(X, Y, [X, Y|Tail]) :-
    adjacent(X,Y, Tail).
  </code></pre>
  
  <p>It works for the basic case of <code>adjacent(c, d, [a, b, c, d, e])</code>, but due to the base case, every other case returns true as well, and I'm stuck on that.</p>
  
  <p>The other problem is that if X is not equal to the first part of the list's head, then it skips past both X and Y and goes to the next 'X'; e.g., if <strong>c</strong> isn't equal to <strong>a</strong>, then it skips past both <strong>a</strong> and <strong>b</strong> and checks if <strong>c</strong> is equal to <strong>c</strong>. This is problematic when, for example, the list is</p>
  
  <pre><code>[a, c, d, e]
  </code></pre>
  
  <p>because it ends up never checking <strong>c</strong> (I believe).</p>
  
  <p>I'm pretty lost on how to reconcile the two issues and turn my logical understanding of what needs to occur into code.</p>
  
  <p>EDIT: Thanks to Christian Hujer's answer, my base case mistake has been corrected, so now I'm just stuck on the second issue.</p>