; Can we accumulate the (nested) potatoes in this dish?
; ------------------------------
; The Little Lisper 3rd Edition
; Chapter 6
; Exercise 10
; Common Lisp
; http://t...content-available-to-author-only...r.com/thelittlelisper
; http://t...content-available-to-author-only...t.com/2010/06/little-lisper-chapter-6-oh-my-gawd-its.html
; http://t...content-available-to-author-only...t.com/2010/06/little-lisper.html
; ------------------------------
(setf l1 '((fried potatoes)(baked (fried)) tomatoes))
(setf l2 '(((chili) chili (chili))))
(setf l3 '())
(setf lat1 '(chili and hot))
(setf lat2 '(baked fried))
(setf a 'fried)
; ------------------------------
(defun add1 (a)
(+ 1 a))
(defun occur* (a lat acc)
(cond
((null lat) acc)
((not(atom (car lat)))
(occur* a (cdr lat) (occur* a (car lat) acc)))
(t (cond
((eq (car lat) a)
(occur* a (cdr lat) (add1 acc)))
(t (occur* a (cdr lat) acc))))))
(print (occur* 'a '(a b c d c (b a)) 0))
;2