I was reading the Simple Database section of Peter Siebel's book Practical Common Lisp with the idea of maintaining a small database of around 50,000 records. I thought doing this in Emacs might be an interesting, and useful, exercise. Emacs Lisp is somewhat compatible with CL except for a few notable differences. The format function used in the above example being one major difference.
Here's the code that contains everything needed to construct, save, and load the database in CL. Can this be modified to work well in Emacs? I omitted the select and where functions but I'd like to include them. Maybe there is a better Emacs way of building and maintaining a database? Personally, I'm using this as an exercise to learn CL and solve an existing problem.
;; Simple Common Lisp database ;; http://www.gigamonkeys.com/book/practical-a-simple-database.html ;; (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 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))))) ; === ; ; Add some records ; (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)) ; (dump-db) ; (save-db "cd.db") ; (load-db "cd.db")