title: How to flatten a 1-2-3 tree into a list?
body: <p>I'm working on a function that converts a tree into a list of integers. My issue is, I can append to the list when I only have to add one or two integers. But I can't seem to be able to append three integers without getting this:</p>
  
  <p><code>[[2], 3, 4]</code>, when I should be getting <code>[2, 3, 4]</code>.</p>
  
  <p>I know that the issue stems from this statement </p>
  
  <pre><code>append([Temp1 | Temp2] , Temp3, L)
  </code></pre>
  
  <p>Where Temp1, Temp2, and Temp3 are the integers I'd like to add. L is the main list that contains all integers from the tree so far.</p>
  
  <hr>
  
  <p>I tried having two append statements, but that returns a <code>false</code> boolean instead of <code>[2, 3, 4]</code>. I tried moving around the <code>[ | ]</code> but I don't think I know enough about them to have made a difference.</p>
  
  <p>The append/3 page also only goes up to concatenating two lists into one. Any help would be greatly appreciated :)</p>
  
  <hr>
  
  <p>Edit: my code is as below, and I added my test example.</p>
  
  <pre><code>chopTree(leaf(_), []).
  chopTree(node1(Leaf, Node), L) :- 
      chopTree(Node, Temp), 
      append([], [Leaf | Temp], L).
  chopTree(node2(Leaf, Node1, Node2), L) :- 
      chopTree(Node1, Temp1), 
      chopTree(Node2, Temp2), 
      append(Temp1, [Leaf | Temp2], L).
  chopTree(node3(_, Node1, Node2, Node3), L) :- 
      chopTree(Node1, Temp1), 
      chopTree(Node2, Temp2), 
      chopTree(Node3, Temp3), 
      append([Temp1 | Temp2] , Temp3, L).
  
  query(E) :- 
      chopTree(node3(1, 
                     node1(2, leaf(1)), 
                     node2(3, leaf(1), leaf(1)), 
                     node1(4, leaf(1))), 
               E). 
  </code></pre>