;; accessors for records of the form (author title year)
(defun author (book) (car book))
(defun title (book)  (car (cdr book)))
(defun year (book)   (car (cdr (cdr book))))

;; return the titles for a list of books
(defun titles (data) 
  (cond ((eq data nil) nil)
	(t (cons (title (car data)) (titles (cdr data))))))


;; a database of books.  defvar defines a constant with the
;; given value.
(defvar books '((Joyce    Ulysses   1922)
		(Melville Moby-Dick 1851)
		(McCarthy Lisp      1960)))


(titles books)

;; a better way to comput titles, using mapping
(defun better-titles (data) 
  (mapcar #'title data))

(better-titles books)



(defun compare-by-year (b1 b2) 
  (< (year b1) (year b2)))

(sort books #'compare-by-year)