title: Prolog - recursive list building
body: <p>for a program I'm writing I need to make a list of lists, with pairs of numbers representing a product and sum of 2 given numbers.</p>
  
  <p>For now I have a function which I can specify how many times I want to add a list to the list, which will be expanded with the full functionality later.</p>
  
  <p>Here's what I have:</p>
  
  <pre><code>s1(0, X).
  s1(Q, X) :-
      N is Q - 1,
      multiply(2, 3, Y),
      A = Y ,
      add(2, 3, Z),
      B = Z,
      addToEnd([A], [B], X),
      s1(N,X).
  
  multiply(A, B, C):-
      C is A * B.
  
  add(A, B, C) :-
      C is A + B.
  
  addToEnd([], L, L).
  addToEnd([H|T], L2, [H|L3]) :-
      addToEnd(T, L2, L3).
  </code></pre>
  
  <p>However, when I run <code>s1(2,X)</code> for example, I get <code>[6,5]</code> returned, then nothing else, it just hangs. When I run <code>s1(0,X)</code>, i get <code>true</code>, then <code>false</code> when I hit <code>;</code></p>
  
  <p>Can anyone help me with this? I can't see what I'm doing wrong, I feel like it should work!</p>
  
  <p>To clarify how I feel this should work: 
  I call <code>s1(2,X).</code> 
  <code>N = 1</code>, <code>[6,5]</code> added to list in <code>X([[6,5]])</code> 
  <code>s1(1,X).</code>
  <code>N=0</code>, <code>[6,5]</code> added to the list in <code>X ([[6,5],[6,5]])</code> 
  <code>s1(0,X).</code> 
  <code>X = [[6,5],[6,5]]</code></p>