- ; Double frying the baked tomatoes (nested atom duplication) 
- ; ------------------------------ 
- ; The Little Lisper 3rd Edition 
- ; Chapter 6 
- ; Exercise 3 
- ; 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 double (a lat) 
-   (cond 
-    ((null lat) '()) 
-    ((eq (car lat) a)(cons a lat)) 
-    (t (cons (car lat) 
-             (double a (cdr lat)))))) 
-   
- (print (double 'bob '(bob the builder))) 
-   
- (defun notatom (lat) 
-   (not (atom lat))) 
-   
- (defun double* (a lat) 
-   (cond 
-    ((null lat) '()) 
-    ((notatom (car lat)) 
-     (cons (double* a (car lat)) 
-           (double* a (cdr lat)))) 
-    ((eq (car lat) a)(cons a lat)) 
-    (t (cons (car lat) 
-             (double* a (cdr lat)))))) 
-   
- (print (double* 'bob '(bob the builder))) 
- ;(BOB BOB THE BUILDER) 
-   
- (print (double* 'bob '((bob) the builder))) 
- ;((BOB BOB) THE BUILDER) 
-   
- (print (double* a l1)) 
- ;((FRIED FRIED POTATOES) (BAKED (FRIED FRIED)) TOMATOES) 
-   
- (print (double* a l2)) 
- ;(((CHILI) CHILI (CHILI))) 
-   
- (print (double* a lat2)) 
- ;(BAKED FRIED FRIED) 
-