実践Common Lispを読んでみる2
- 作者: Peter Seibel,佐野匡俊,水丸淳,園城雅之,金子祐介
- 出版社/メーカー: オーム社
- 発売日: 2008/07/26
- メディア: 単行本(ソフトカバー)
- 購入: 8人 クリック: 192回
- この商品を含むブログ (69件) を見る
- mapcarすごい。
- lambda出てきた。
みたいな感じ。
以下、ソースコード。
;; (defun select-by-artist (artist) ;; (remove-if-not ;; #'(lambda (cd) (equal (getf cd :artist) artist)) ;; *db*)) (defun select (selector-fn) (remove-if-not selector-fn *db*)) ;; (defun artist-selector (artist) ;; #'(lambda (cd) (equal (getf cd :artist) artist))) (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 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*))) (defun delete-rows (selector-fn) (setf *db* (remove-if selector-fn *db*)))
http://dl.getdropbox.com/u/228440/veleno-samples/lisp-samples/sample.lisp