Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble formatting first exercise from Practical Common LISP

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?

like image 740
user151841 Avatar asked May 30 '26 01:05

user151841


1 Answers

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.

like image 89
Dwight Holman Avatar answered Jun 01 '26 01:06

Dwight Holman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!