fork download
  1. ; Finding the hidden chili and separating them out
  2. ; ------------------------------
  3. ; The Little Lisper 3rd Edition
  4. ; Chapter 6
  5. ; Exercise 1
  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. (atom 'chili)
  20. (atom '(chili))
  21. (atom (car '(chili)))
  22. (consp (car l2))
  23.  
  24. (defun notatom (lat)
  25. (not (atom lat)))
  26.  
  27. (notatom 'a)
  28. (notatom '(a))
  29.  
  30. (defun down* (lat)
  31. (cond
  32. ((null lat) '())
  33. ((notatom (car lat))
  34. (cons (down* (car lat))
  35. (down* (cdr lat))))
  36. (t (cons (list (car lat))
  37. (down* (cdr lat))))))
  38.  
  39. (print (down* (list 'bob)))
  40. ;((BOB))
  41.  
  42. (print (down* l2))
  43. ;((((CHILI)) (CHILI) ((CHILI))))
  44.  
  45. (print (down* l3))
  46. ;NIL;
  47.  
  48. (print (down* lat1))
  49. ;((CHILI) (AND) (HOT))
  50.  
Success #stdin #stdout 0s 10592KB
stdin
Standard input is empty
stdout
((BOB)) 
((((CHILI)) (CHILI) ((CHILI)))) 
NIL 
((CHILI) (AND) (HOT))