Ex1.4 atomの出現回数
PAIPの解答そのまま。
PAIPの解答を見てcondのt節の後の式は改行しないで書く慣習であることに気づく。
;;; exercise 1.4 [m] Write a function that counts the number of times an expression ;;; occurs anywarere whthin another expression. Example: (count-anywhere 'a '(a ;;; ((a) b) a)) (defun count-anywhare (exp1 exp2) (cond ((eql exp1 exp2) 1) ((atom exp2) 0) (t (+ (count-anywhare exp1 (first exp2)) (count-anywhare exp1 (rest exp2)))))) (count-anywhare 'a '(a (b c (d a) a) a)) ;; => 4 (#x4, #o4, #b100)