title: Prolog, counter
body: <p>I want to calculate , in two lists (same lenght), the number of elements that are equal and in the same position. 
  For example:
  Lets say we have the lists A = [3,6,7,9]  and  B = [2,6,4,9], i want to be printed in the screen the message, "2 bulls found".</p>
  
  <p>So far i have made this:</p>
  
  <pre><code>bulls([],[]).
  bulls([Ha|Ta],[Hb|Tb]) :-
      Ha = Hb,
      writeln('bull found'),
      bulls(Ta,Tb);
      bulls(Ta,Tb).
  </code></pre>
  
  <p>Every time an element that exists in the same place in both lists, the message 'bull found' is printed.
  And in my mind i want to make something like this:</p>
  
  <pre><code>bulls([],[],_).
  bulls([Ha|Ta],[Hb|Tb],Counter) :-
      Ha = Hb,
      NewCounter is Counter + 1,
      bulls(Ta,Tb,NewCounter);
      bulls(Ta,Tb,NewCounter).
  
  bulls(List1,List2):- bulls(List1,List2,0).
  </code></pre>
  
  <p><code>bulls</code> is called from another rule that passes the lists two it.
  How do i make it so it prints the value of 'bulls' to the screen. Any help?</p>
  
  <hr>
  
  <p><strong>Edit</strong>
  So after <strong>Suki's</strong> post, i made this test program testing 2 lists:</p>
  
  <pre><code>bulls([],[],X), write(X), write('bulls found'),fail.
  bulls([Ha|Ta],[Hb|Tb],Counter) :-
      Ha = Hb,
      NewCounter is Counter + 1,
      bulls(Ta,Tb,NewCounter);
      bulls(Ta,Tb,NewCounter).
  
  check(List1,List2):- 
      bulls(List1,List2,0).
  
  
  start:-
      A=[1,1,1,1],
      B=[2,1,2,1],
      writeln(A),writeln(B),
      check(A,B).
  </code></pre>
  
  <p>and i get this result</p>
  
  <pre><code>1 ?- start.
  [1,1,1,1]
  [2,1,2,1]
  ERROR: bulls/3: Arguments are not sufficiently instantiated
  </code></pre>
  
  <p>what am i doing wrong?</p>