fork download
  1. ; LISP asking three questions about the fried potatoes
  2. ; ------------------------------
  3. ; The Little Lisper 3rd Edition
  4. ; Chapter 6
  5. ; Exercise 4
  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. ;Function lat? from Chapter 2
  19. (defun lat? (l)
  20. (cond
  21. ((null l) t)
  22. ((atom (car l)) (lat? (cdr l)))
  23. (t nil)))
  24. (print (lat? '(bacon (and eggs))))
  25. ;F
  26.  
  27. (print (lat? '(bacon and eggs)))
  28. ;T
  29.  
  30. ; Why does it have to ask three questions? (and not two like other functions in chapter 2)
  31. ;; The only other real function is member - which determines if a flat-list contains an atom or not
  32. ;; The first question is the termination of the recursion on the list which is being examined
  33. ;; The second question is the truth test - does this list contain atoms only
  34. ;; The third question is if this list contains a non-atom (ie a list) - then fail
  35. ;;; So the reason we ask three questions is because the definition of lat? is two-fold
  36. ;;; (both contains atoms and doesn't contain lists)
  37. ; Why does lat not have to recur on the car?
  38. ;; Because lat? is asking the questions whether this is a 'flat list' ie "Is this is a list but not a list of lists."
  39.  
Success #stdin #stdout 0.02s 10536KB
stdin
Standard input is empty
stdout
NIL 
T