《实用common lisp编程》中问题求教
lisp吧
全部回复
仅看楼主
level 3
我用的win7系统,
lispbox-0.7
我在看第三章:简单数据库的时候,按照书上的代码写的程序:
(defvar *db* nil)
(defun make-cd (title artist rating ripped)
(list :title title :artist artist :rating rating :ripped ripped))
(defun add-record (cd) (push cd *db*))
(defun dump-db()
(dolist (cd *db*)
(format t "~{~a: ~10t~a~%~}~%" cd)))
(defun prompt-read (prompt)
(format *query-io* "~a: " prompt)
(force-output *query-io*)(read-line *query-io*))
(defun prompt-for-cd()
(make-cd(prompt-read "Title")
(prompt-read "Artist")
(or (parse-integer (prompt-read "Rating") :junk-allowed t) 0)
(y-or-n-p "Ripped [Y/n]")))
(defun add-cds ()
(loop (add-record (prompt-for-cd))
(if (not (y-or-n-p "Another? [y/n]: ")) (return))))
(defun save-db (filename)
(with-open-file (out filename :direction :output :if-exists :supersede)
(with-standard-io-syntax(print *db* out))))
在调用最后一个函数save-db的时候,出错了,错误信息如下:
Undefined function SAVE-DB called with arguments ("f:/lispCode/make-cd.dat") . [Condition of type CCL::UNDEFINED-FUNCTION-CALL]
跪求同学们指教啊
2013年08月02日 15点08分 1
level 7
貌似你的with-standard-io-syntax后少一个空格
2013年08月03日 02点08分 2
代码里,这里是换行的。贴上来就乱了
2013年08月03日 04点08分
level 7
这个是我以前敲的,所有功能都正常,你试下吧
;
(defun make-cd (title artist rating ripped)
"make mp3 to be a cd..."
(list :title title :artist artist :rating rating :ripped ripped))
(defvar *db* nil
"mp3 database...")
(defun add-record (cd)
"insert a mp3 record into mp3 database..."
(push cd *db*))
(defun dump-db ()
"show contents of mp3 db..."
(dolist (cd *db*)
(format t "~{~a: ~10t~a~%~}~%" cd)))
(defun dump-db-1 ()
"show contents of mp3 db..."
(format t "~{~{~a: ~10t~a~%~}~%~}" *db*))
(defun prompt-read (prompt)
(format *query-io* "~a: " prompt)
(force-output *query-io*)
(read-line *query-io*))
(defun prompt-for-cd ()
(make-cd
(prompt-read "Title")
(prompt-read "Artist")
(or (parse-integer (prompt-read "Rating")))
(y-or-n-p "Ripped [y/n]")))
(defun add-cds ()
(loop (add-record (prompt-for-cd))
(if (not (y-or-n-p "Another? [y/n]: "))
(return))))
(defun save-db (filename)
(with-open-file (out filename
:direction :output
:if-exists :supersede)
(with-standard-io-syntax
(print *db* out))))
(defun open-db (filename)
(with-open-file (in filename)
(with-standard-io-syntax
(setf *db* (read in)))))
(defun select-by-artist (artist)
(remove-if-not
#'(lambda (cd) (equal (getf cd :artist) artist))
*db*))
(defun where (&key title artist rating (ripped nil ripped-p))
#'(lambda (cd)
(and
(if title (equal (getf cd :title) title) t)
(if artist (equal (getf cd :artist) artist) t)
(if rating (equal (getf cd :rating) rating) t)
(if ripped-p (equal (getf cd :ripped) ripped) t))))
(defun select (select-fn)
(remove-if-not select-fn *db*))
(defun update (selector-fn &key title artist rating (ripped nil ripped-p))
(setf *db*
(mapcar
#'(lambda (row)
(when (funcall selector-fn row)
(if title (setf (getf row :title) title))
(if artist (setf (getf row :artist) artist))
(if rating (setf (getf row :rating) rating))
(if ripped-p (setf (getf row :ripped) ripped)))
row) *db*)))
2013年08月03日 02点08分 3
level 7
哎,传上去格式会乱
2013年08月03日 02点08分 4
今天又弄好了,不知道怎么回事
2013年08月03日 04点08分
1