title: Is there a way to sum only the integers in a list of pairs that contain a letter and an integer in Prolog?
body: <p>I'm having trouble figuring out how to find the sum of the integers that are in a list of pairs like so:</p>
  
  <pre><code>[[a, 1], [b, 2], [c, 3], [d, 4]]
  </code></pre>
  
  <p>I tried something like this, since it is reminiscent of a regular sum function:</p>
  
  <pre><code>sum([], 0).
  sum([[_,Head]|[_,Tail]], Sum) :-
      sum([_,Tail], Sum2),
      Sum is Head+Sum2.
  </code></pre>
  
  <p>With the call being:</p>
  
  <pre><code>sum([[a, 1], [b, 2], [c, 3], [d, 4]], Total),
  write('Sum = '), write(Total).
  </code></pre>
  
  <p>But that doesn't work. It prints out false, when it should print out the sum, which would be 10 here.</p>