; LISP asking three questions about the fried potatoes
; ------------------------------
; The Little Lisper 3rd Edition
; Chapter 6
; Exercise 4
; 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)
; ------------------------------
;Function lat? from Chapter 2
(defun lat? (l)
(cond
((null l) t)
((atom (car l)) (lat? (cdr l)))
(t nil)))
(print (lat? '(bacon (and eggs))))
;F
(print (lat? '(bacon and eggs)))
;T
; Why does it have to ask three questions? (and not two like other functions in chapter 2)
;; The only other real function is member - which determines if a flat-list contains an atom or not
;; The first question is the termination of the recursion on the list which is being examined
;; The second question is the truth test - does this list contain atoms only
;; The third question is if this list contains a non-atom (ie a list) - then fail
;;; So the reason we ask three questions is because the definition of lat? is two-fold
;;; (both contains atoms and doesn't contain lists)
; Why does lat not have to recur on the car?
;; Because lat? is asking the questions whether this is a 'flat list' ie "Is this is a list but not a list of lists."