title: Prolog Assignment
body: <p>This is the question for one of my assignments:</p>
  
  <blockquote>
    <p>Write <code>repCount(L, X, N)</code> which is true when <code>N</code> is the number of occurrences of <code>X</code> in list <code>L</code>.</p>
  </blockquote>
  
  <p>Here's my code where I try to tackle the problem recursively:</p>
  
  <pre><code>repCount([], X, N) :-
     N is 0.
  repCount([H|T], X, N) :-
     count([H|T], X, N).
  
  count([], X, 0).
  count([H|T], X, N) :-
     count(T, X, N1), 
     X =:= H,
     N is N1 + 1.
  </code></pre>
  
  <p>And it works when I supply a list full of identical numbers like this:</p>
  
  <pre><code>?- repCount([2,2,2], 2, N).
  N = 3.
  </code></pre>
  
  <p>But if I supply a list with at least one different value:</p>
  
  <pre><code>?- repCount([2,2,22], 2, N).
  false.
  </code></pre>
  
  <p>It returns <code>false</code>. I cannot figure out why this happens or how to change it to 'skip' the non-matching value, rather than declare the whole thing false. Any input is appreciated.</p>