- ; Can we accumulate the potatoes in this dish? 
- ; ------------------------------ 
- ; The Little Lisper 3rd Edition 
- ; Chapter 6 
- ; Exercise 9 
- ; 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) 
-   (cond 
-    ((null lat) 0) 
-    (t (cond 
-        ((eq (car lat) a) 
-         (add1 (occur a (cdr lat)))) 
-        (t (occur a (cdr lat))))))) 
-   
- (print (occur 'a '(a b c d c (b a)))) 
-   
- (defun occur (a lat acc) 
-   (cond 
-    ((null 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)) 
-   
- (defun occur (a lat acc) 
-   (cond 
-    ((null lat) acc) 
-    (t (occur a (cdr lat)  
-              (cond  
-               ((eq (car lat) a) 
-                (add1 acc)) 
-               (t acc)))))) 
-   
- (print (occur 'a '(a b c d c (b a)) 0)) 
-   
- ;The original value for acc is 0 
-