title: Prolog: Matching One or More Anonymous Variables
body: <p>[_, [ X , _ ],_] will match a list like [d, [X,a], s]. Is there a way to match it to any pattern where there is one or more anonymous variables? ie. [[X,a],s] and [[d,a],[p,z], [X,b]] would match?</p>
  
  <p>I am trying to write a program to count the elements in a list ie. [a,a,a,b,a,b] => [[a,4],[b,2]] but I am stuck:</p>
  
  <pre><code>listcount(L, N) :-  listcountA(LS, [], N).
  listcountA([X|Tail], [? [X, B], ?], N) :- B is B+1, listcountA(Tail, [? [X,B] ?], N).
  listcountA([X|Tail], AL, N) :- listcountA(Tail, [[X,0]|AL], N).
  </code></pre>
  
  <p>Thanks.</p>