#!/usr/local/bin/sbcl --script (defun foo (&key a b c) (list a b c)) (format t "~a~%" (foo :a 1 :b 2 :c 3)) (format t "~a~%" (foo :c 3 :b 2 :a 1)) (format t "~a~%" (foo :a 1 :c 3) ) (format t "~a~%" (foo)) (defun foo (&key a (b 20) (c 30 c-p)) (list a b c c-p)) (format t "~a~%" (foo :a 1 :b 2 :c 3)) (format t "~a~%" (foo :c 3 :b 2 :a 1)) (format t "~a~%" (foo :a 1 :c 3) ) (format t "~a~%" (foo)) (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 "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) ;select (format t "~a~%" "select") (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))) (format t "~a~%" (select (artist-selector "Dixie Chicks"))) ;where (format t "~a~%" "where") (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)))) (format t "~a~%" (select (where :artist "Dixie Chicks"))) (format t "~a~%" (select (where :rating 10 :ripped nil))) ;update (format t "~a~%" "update") (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*))) (format t "~a~%" (select (where :artist "Dixie Chicks"))) (update (where :artist "Dixie Chicks") :rating 11) (format t "~a~%" (select (where :artist "Dixie Chicks"))) ;delete (format t "~a~%" "delete") ;(dump-db) (defun delete-rows (selector-fn) (setf *db* (remove-if selector-fn *db*))) (delete-rows (where :artist "Dixie Chicks")) ;(select (where :rating 10 :ripped nil) (dump-db)