It's chapter 11 exercise 11.22 d
(defun count-bases (dna)
(let ((dnaCnt '((A 0) (T 0) (G 0) (C 0))))
(labels ((count-element (x)
(incf (second (assoc x dnaCnt))))
(count-recurse (x)
(cond ((null x) t)
((atom (first x)) (and (count-element (first x))
(count-recurse (rest x))))
(t (and (count-recurse (first x))
(count-recurse (rest x)))))))
(count-recurse dna)
dnaCnt)))
The code is compiled without a problem.
When I run the program first time by evaluating
(count-bases '((g c) (a t) (t a) (t a) (c g)))
It gives the correct output:
((A 3) (T 3) (G 2) (C 2))
However, if I run it second time,
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 388 |
Nodes: | 16 (2 / 14) |
Uptime: | 09:56:44 |
Calls: | 8,221 |
Files: | 13,122 |
Messages: | 5,872,631 |