EX1.3 リスト中のatomの数を数える
;;; Exercise 1.3 [m] Write a function that counts the number of atoms in an expression. ;;; For example: (count-atoms '(a (b) c)) =>3. Notice that there is something of an ;;; ambiguity in this: shoud (a nil c) count as three atoms or as two, because it is ;;; equivalent to (a () c)? (defun count-atoms (exp) (do ((e exp (rest e)) (atoms 0)) ((null e) atoms) (cond ((atom (car e)) (incf atoms)) (t (incf atoms (count-atoms (car e))))))) (count-atoms '(a () c)) ;; => 3 (#x3, #o3, #b11) (count-atoms '(a (b) c)) ;; => 3 (#x3, #o3, #b11)