title: Trying to get a list element by index in prolog
body: <p>This is what I have so far:</p>
  
  <pre><code>getByIndex([X],0,E):- E is X.
  getByIndex([H|_],0,E):- E is H.
  getByIndex([_|T],I,E) :- getByIndex(T,I-1,E).
  </code></pre>
  
  <p>It seems to work when requesting the first element, but not subsequent elements, and I can't quite figure out why.</p>
  
  <p>I'm aware that there might be a built-in solution in something like SWI-prolog, but I'd like to understand why this fails.</p>