title: A combination of a list given a length followed by a permutation in Prolog?
body: <p>I need a predicate to return a list with all combinations of the input list, and the list result size is in the second param, the predicate would be like this </p>
  
  <pre><code>permutInListN( +inputList, +lengthListResult, -ListResult), 
  </code></pre>
  
  <p>example: </p>
  
  <pre><code>permutInListN([1,2,3],2,L).
  ? L=[1,2].
  ? L=[2,1].
  ? L=[1,3].
  ? L=[3,1].
  ? L=[2,3].
  ? L=[3,2].
  </code></pre>
  
  <p>Combinations of <code>[1,2,3]</code> in a list <code>L</code> with length <code>2</code>.
  with no repetitions maybe using setoff. </p>
  
  <p>this is my code but it doesn't work at all , no generate all solutions</p>
  
  <pre><code>permutInListN(_, 0, []).
  permutInListN([X|Xs], N, [X|Ys]) :- N1 is N-1, permutInListN(Xs,N1,Ys).
  permutInListN([_|Xs], N, Y) :- N&gt;0, permutInListN(Xs,N,Y).
  
  ?permutInListN([1,2,3],2,L).
  L = [1, 2]
  L = [1, 3]
  L = [2, 3]
  </code></pre>
  
  <p>thanks in advance.</p>