Code: Select all

```
(COUNT-BASES '((G C) (A T) (T A) (T A) (C G)))
```

Code: Select all

```
((A 3) (T 3) (G 2) (C 2))
```

Code: Select all

```
(COUNT-BASES '(A G T A C T C T))
```

Code: Select all

```
((A 2) (T 3) (G 1) (C 2))
```

Code: Select all

```
(defun count-bases (dna)
(let ((num-a 0)
(num-t 0)
(num-g 0)
(num-c 0))
(defun count-nucleotides (x)
(cond ((eq x 'a) (incf num-a))
((eq x 't) (incf num-t))
((eq x 'g) (incf num-g))
((eq x 'c) (incf num-c))))
(dolist (base-pair dna
(list (list 'a num-a) (list 't num-t) (list 'g num-g) (list 'c num-c)))
(cond ((listp base-pair) (count-nucleotides (car base-pair))
(count-nucleotides (cadr base-pair)))
(t (count-nucleotides base-pair))))))
```

Code: Select all

```
(defstruct base-count
(num-a 0)
(num-t 0)
(num-g 0)
(num-c 0))
```

The function works properly under both Clozure and LispWorks, though I get a warning from LispWorks when I compile it:

Code: Select all

```
The following function is undefined:
COUNT-NUCLEOTIDES which is referenced by COUNT-BASES
```

Moreover, is it good Lisp style to do something like this?