title: Understanding Difference Lists
body: <p>I'm trying to understand difference lists in Prolog, but I'm struggling to actually implement one properly, everytime I try to do it, I get a list of lists, but that's not what I want. I'm trying to implement an append predicate, but having little luck so far. Few attempts, all of which don't work.</p>
  
  <pre><code>app(X, Y, Z) :- Z = [X|Y].
  
  ?- app([a,b,c], [z], Z).
  Z = [[a,b,c],z].
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>app(X, Y, Z) :- Z = [X|Hole], Hole = Y.
  </code></pre>
  
  <p>Same results as the first one, (they do seem to be basically the same). I have an example in a book that does work (although it's not a predicate), and I don't understand the difference. <code>X</code> becomes instantiated to the proper answer <code>[a,b,c,z]</code>, how is that much different than my second example?</p>
  
  <pre><code>X = [a,b,c|Y], Y = [z].
  </code></pre>
  
  <p>What am I missing? Thanks.</p>