実践Common Lispを読んでみる
と言う訳で↓
- 作者: Peter Seibel,佐野匡俊,水丸淳,園城雅之,金子祐介
- 出版社/メーカー: オーム社
- 発売日: 2008/07/26
- メディア: 単行本(ソフトカバー)
- 購入: 8人 クリック: 192回
- この商品を含むブログ (69件) を見る
感想
- 日本語のリテラル通らない。よくわからない。"coding system iso-latin-1-unix not suitable for..."とかエラーが出る。とりあえず放置。
- formatよくわからない。…まあそのうち。
- readすごい。
続きはソースコード。
(defun make-cd (title artist rating ripped) (list :title title :artist artist :rating rating :ripped ripped)) (defvar *db* nil) (defun add-record (cd) (push cd *db*)) ;(add-record (make-cd "test" "title" 2 nil)) ;(add-record (make-cd "test2" "sample" 3 nil)) (defun dump-db () (dolist (cd *db*) (format t "~{~a:~10t~a~%~}~%" cd))) ;(format t "~a" "Dixie Chicks") ;(format t "~a" :title) ;(defun dump-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") :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)))) (defun load-db (filename) (with-open-file (in filename) (with-standard-io-syntax (setf *db* (read in)))))
ファイルは↓
http://dl.getdropbox.com/u/228440/veleno-samples/lisp-samples/sample.lisp