title: Prolog recursing endlessly in getList predicate
body: <p>This predicate is intended to tell if the list has the element in it and add it to a new list. However, once I finish recursing through and I have the correct list being returned, it recurses backwards until it ends up at the beginning again and then recurses through it again -- endlessly.</p>
  
  <pre><code>getList([],X,[]).
  getList([H|T],Side,Others) :-
      (length(T,3)),
      (H == Side),
      append([],[H],NewList),
      getList(T,Side,NewList).
  getList([H|T],Side,Others) :-
      (H == Side),
      append(Others, [Side], Others1),
      getList(T,Side,Others1). // where it backwards recurses after finishing
  getList([E],X,[]).
  </code></pre>
  
  <p>Please help me determine WHY it does this as well as find a solution.</p>