title: Passing the Results of a Prolog Predicate
body: <p>How does one evaluate the result of a prolog predicate to pass as an argument?
  I am trying to write code to reverse pairs of elements in a list:</p>
  
  <pre><code>swap([A,B,C,D,E,F],R).
  </code></pre>
  
  <p>I want the result:</p>
  
  <pre><code>[B,A,D,C,F,E]
  </code></pre>
  
  <p>but I get this result:</p>
  
  <pre><code>append(append(append([],[B,A],[D,C],[F,E])))
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>swap(L,R) :- swapA(L,[],R).
  swapA([],A,A).
  swapA([H,H2|T],A,R) :-  swapA(T, append(A,[H2,H]), R).
  </code></pre>
  
  <p>Thanks.</p>