我开始学习实用的通用lisp,第一个练习是编写simple database。我在cygwin上使用gnu clisp 2.48(2009-07-28)。
这段代码,我已经和这本书比较了好几次,并没有像书上说的那样产生输出
(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)
我明白了
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~%~}~%"
|
我不太了解
format
或LISP,无法排除故障书上说我应该得到数据库中所有记录的清单出什么事了? 最佳答案
首先,让我们看看从(制作CD)返回:
[12]> (make-cd "Home" "Dixie Chicks" 9 t)
(:TITLE "Home" :ARTIST "Dixie Chicks" :RATING 9 :RIPPED)
您没有包含
:ripped
的值将(制作cd)更改为:(defun make-cd (title artist rating ripped)
(list :title title :artist artist :rating rating :ripped ripped))
注意
ripped
之后的:ripped
。