title: assoc function in Common Lisp and 2 questions
body: <p>I've got a list which keeps occurances of letters in a sentence:</p>
  
  <pre><code>(setf mylist '((a 1) (b 2) (a 1) (b 1) (o 2) (m 1))) ; "abba boom"
  </code></pre>
  
  <p>I'd like to associate all pairs having for instance the letter b:</p>
  
  <pre><code>(assoc 'b mylist) ; =&gt; returns just the first occurance of b: (B 2)
  </code></pre>
  
  <p>How to get all pairs associated with b and list them? e.g.</p>
  
  <pre><code>(my-assoc 'b mylist) ; =&gt; ((B 2) (B 1))
  </code></pre>
  
  <p>2-  How to write a function which will group the letters along with the sum of their occurances? e.g.</p>
  
  <pre><code>(my-group-sum mylist) ; =&gt; ((A 2) (B 3) (O 2) (M 1))
  </code></pre>
  
  <p>Here is my take, assuming that <code>my-assoc</code> as described above, exists:</p>
  
  <pre><code>(defun my-group-sum (lst) 
    (loop for (letter num) in lst do 
       (let ((temp (my-assoc letter lst)) 
             (occurance 0)) 
            (dolist (pair temp) 
               (incf occurance (cdr pair)))); cdr should be "second" 
            collect (letter occurance)))
  </code></pre>
  
  <p>Note: This code is not compiled, nor tested. It's very likely to be erroneous even if the <code>my-assoc</code> function was available. It's just for demonstation purposes.</p>