title: Prolog lists Error: out of global stack
body: <p>I'm trying to write a rule in prolog
  <code>adjacent(X,Y,Zs)</code>, as <code>true</code> if <code>X</code> and <code>Y</code> are adjacent to each other in the list <code>Zs</code>.</p>
  
  <p>I currently have:</p>
  
  <pre><code>append([],L,L).
  append([H|T],L,[H|LT]):-append(T,L,LT).
  sublist(S,L):-append(_,S,P),append(P,_,L).
  adjacent(X,Y,Zs):-sublist([X,Y],Zs).
  </code></pre>
  
  <p>test:</p>
  
  <pre><code>1 ?- sublist([1,2],[1,2,3,4]).
  true .
  
  2 ?- sublist([1,3],[1,2,3,4,5]).
  ERROR: Out of global stack
  3 ?- 
  </code></pre>
  
  <p>Do you guys have any ideas? Thanks in advance.</p>