title: Prolog: append is failing inside loop
body: <p>I have the following Prolog code:</p>
  
  <pre><code>my_function(A):-
     my_function(A,[],1).
  
  my_function(A,List,Num):-
     Num_new is Num+1,
     generateL(O,S,L),
     write(L),nl,
     %append(L,List,List_New),
     (  Num_new &lt; 20 -&gt; my_function(A,List_New,Num_new)  ).
  </code></pre>
  
  <p>Which is working. It loops through 19 times, calls <code>generateL</code> which generates a new term <code>L</code> which I print to the screen.</p>
  
  <p>I now want on each iteration to append <code>L</code> to a list <code>List</code> to create a new list <code>List_New</code> which is then passed through in the recursive loop as <code>List</code> such that in the next iteration this is the list that <code>L</code> is again appended to. </p>
  
  <p>I have attempted to do this by writing the <code>append</code> statement which is commented out above. The problem is that this statement is failing - I believe because <code>List_New</code> is not seen as a variable, but rather as a pre-existing list, thus append is testing whether <code>List_New</code> is indeed <code>L</code> and <code>List</code> appended together, as opposed to creating a new list <code>List_New</code>.</p>
  
  <p>Any ideas on how to solve this? Thanks!</p>