I'm beginning to work through Practical Common LISP and the first exercise is to write a simple database. I'm using GNU CLISP 2.48 (2009-07-28) on cygwin.
This code, which I've compared against the book several times, doesn't produce output the way the book says it should
(defun make-cd (title artist rating ripped)
(list :title title :artist artist :rating rating :ripped))
(defvar *db* nil)
(defun add-record (cd) (push cd *db*))
(add-record (make-cd "Roses" "Kathy Mattea" 7 t))
(add-record (make-cd "Fly" "Dixie Chicks" 8 t))
(add-record (make-cd "Home" "Dixie Chicks" 9 t))
(defun dump-db ()
(dolist (cd *db*)
(format t "~{~a:~10t~a~%~}~%" cd)))
(dump-db)
I get
TITLE: Home
ARTIST: Dixie Chicks
RATING: 9
RIPPED:
*** - There are not enough arguments left for this format directive.
Current point in control string:
"~{~a:~10t~a~%~}~%"
|
I don't understand format
or LISP well enough to being to troubleshoot. The book says I should be getting a list of all the records in the database. What has gone wrong?
First, let's look at the return from (make-cd):
[12]> (make-cd "Home" "Dixie Chicks" 9 t)
(:TITLE "Home" :ARTIST "Dixie Chicks" :RATING 9 :RIPPED)
You aren't including a value for :ripped
! Change (make-cd) to:
(defun make-cd (title artist rating ripped)
(list :title title :artist artist :rating rating :ripped ripped))
Note the ripped
after :ripped
.