title: How do I append lists in Prolog?
body: <p>How do I append lists in Prolog? I've searched on the Internet and I found this  (from <a href="http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/2_7.html" rel="noreferrer">http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/2_7.html</a>)</p>
  
  <pre><code>append([X|Y],Z,[X|W]) :- append(Y,Z,W).  
  append([],X,X).
  </code></pre>
  
  <p>So it gets the <code>Z</code> by removing the elements of <code>[X|Y]</code> in <code>[X|W]</code>. But how do I append two lists together? </p>
  
  <p>Example,</p>
  
  <pre><code>appendlist([1,2],[3,4,5],X).
  </code></pre>
  
  <p>The result will be <code>X = [1,2,3,4,5]</code>.</p>
  
  <p>Also I don't know what happening in the recursion. (I traced it but didn't understand)</p>
  
  <p><strong>EDIT:</strong> What I want to know is how it should be coded to function like the predefined <code>append()</code> in Prolog.</p>