title: Prolog beginner - reverse output list
body: <p>I'm a Prolog beginner and I'm looking for a way to reverse the output of this code.</p>
  
  <pre><code>fib(N, F) :- fib(N, 0, [1], F).
  fib(0, _, A, A).
  fib(N, A, [B|Bs], F) :- N1 is N - 1, Sum is A + B, fib(N1, B, [Sum,B|Bs], F).
  </code></pre>
  
  <p>The code calculates the Fibonacci numbers for the value of <code>N</code> and prints the result in <code>F</code>.</p>
  
  <p>For example <code>fib(4,X).</code> produces <code>X=[5,3,2,1,1]</code>. What I want is <code>X=[1,1,2,3,5]</code> (reversed output).</p>
  
  <p>I can't seem to bring it to this format, and preserve its tail recursive property.</p>
  
  <p>thanks for any help</p>