title: Prolog: Create sublist, given two indices
body: <p>Basically, I need to create a predicate of the form sublist(S,M,N,L), where S is a new list formed from the elements of L between index M and index N, inclusive.</p>
  
  <p>Here's where I've gotten:</p>
  
  <pre><code>sublist([],_,_,[]).
  sublist([],M,N,_) :- (M &gt; N).
  sublist(S,M,N,L) :- sublist2(S,M,N,L,-1).
  sublist2([H|T],St,En,[H2|T2],Idx) :-
     (Idx2 is Idx + 1,
     St =&lt; Idx2,
     En &gt;= Idx2,
     H = H2,
     sublist2(T,St,En,T2,Idx2);
     Idx2 is Idx + 1,
     sublist2(T,St,En,T2,Idx2)).
  </code></pre>
  
  <p>As with all my prolog problems, I feel I'm making it way more complicated than it should be. I've got the base cases right, but anything else evaluates to false. Any advice for this problem, and just general approach to prolog? I understand the language for the most part, but I can't seem to see the simple solutions.</p>