title: Returning a value after a recursion in Prolog
body: <p>I decided to study some logic programming and I stumbled across a problem.
  It is programmed in SWI Prolog.</p>
  
  <pre><code>test(A, B, N):-
   nonvar(B),
   B = final,
   true.
  
  test(A, B, N):-
   N &gt; 2,
   test(A, final, N).
  
  test(A, B, N):-
   N1 is N + 1,
   test(N1, B, N1).
  </code></pre>
  
  <p>It is just a sample with no real use except it is driving me crazy.</p>
  
  <p>The problem is that when the code reaches true then it starts tracking back and answers "true". But I need to "return" value A. How do I do that?</p>