fork download
  1. ; Double frying the baked tomatoes (nested atom duplication)
  2. ; ------------------------------
  3. ; The Little Lisper 3rd Edition
  4. ; Chapter 6
  5. ; Exercise 3
  6. ; Common Lisp
  7. ; http://t...content-available-to-author-only...r.com/thelittlelisper
  8. ; http://t...content-available-to-author-only...t.com/2010/06/little-lisper-chapter-6-oh-my-gawd-its.html
  9. ; http://t...content-available-to-author-only...t.com/2010/06/little-lisper.html
  10. ; ------------------------------
  11. (setf l1 '((fried potatoes)(baked (fried)) tomatoes))
  12. (setf l2 '(((chili) chili (chili))))
  13. (setf l3 '())
  14. (setf lat1 '(chili and hot))
  15. (setf lat2 '(baked fried))
  16. (setf a 'fried)
  17. ; ------------------------------
  18.  
  19. (defun double (a lat)
  20. (cond
  21. ((null lat) '())
  22. ((eq (car lat) a)(cons a lat))
  23. (t (cons (car lat)
  24. (double a (cdr lat))))))
  25.  
  26. (print (double 'bob '(bob the builder)))
  27.  
  28. (defun notatom (lat)
  29. (not (atom lat)))
  30.  
  31. (defun double* (a lat)
  32. (cond
  33. ((null lat) '())
  34. ((notatom (car lat))
  35. (cons (double* a (car lat))
  36. (double* a (cdr lat))))
  37. ((eq (car lat) a)(cons a lat))
  38. (t (cons (car lat)
  39. (double* a (cdr lat))))))
  40.  
  41. (print (double* 'bob '(bob the builder)))
  42. ;(BOB BOB THE BUILDER)
  43.  
  44. (print (double* 'bob '((bob) the builder)))
  45. ;((BOB BOB) THE BUILDER)
  46.  
  47. (print (double* a l1))
  48. ;((FRIED FRIED POTATOES) (BAKED (FRIED FRIED)) TOMATOES)
  49.  
  50. (print (double* a l2))
  51. ;(((CHILI) CHILI (CHILI)))
  52.  
  53. (print (double* a lat2))
  54. ;(BAKED FRIED FRIED)
  55.  
Success #stdin #stdout 0.02s 10552KB
stdin
Standard input is empty
stdout
(BOB BOB THE BUILDER) 
(BOB BOB THE BUILDER) 
((BOB BOB) THE BUILDER) 
((FRIED FRIED POTATOES) (BAKED (FRIED FRIED)) TOMATOES) 
(((CHILI) CHILI (CHILI))) 
(BAKED FRIED FRIED)