title: Building and maintaining a database in Emacs?
body: <p>I was reading the <a href="http://www.gigamonkeys.com/book/practical-a-simple-database.html" rel="noreferrer">Simple Database</a> section of Peter Siebel's book <a href="http://www.gigamonkeys.com/book/" rel="noreferrer">Practical Common Lisp</a> 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 <a href="http://www.gnu.org/software/emacs/manual/html_node/cl/Porting-Common-Lisp.html" rel="noreferrer">notable differences</a>.  The <strong>format</strong> function used in the above example being one major difference.</p>
  
  <p>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 <strong>select</strong> and <strong>where</strong> 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.</p>
  
  <pre>
  ;; 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")
  
  </pre>