<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -7,10 +7,10 @@
 (defstruct cd :title :artist :rating :ripped)
 
 ; pass db (not mutable data)
-(defn add-records [db &amp; cd] (concat db cd))
+(defn add-records [db &amp; cd] (into db cd))
 
 (defn init-db []
-  (add-records '() 
+  (add-records #{} 
 	      (struct cd &quot;Roses&quot; &quot;Kathy Mattea&quot; 7 true)
 	      (struct cd &quot;Fly&quot; &quot;Dixie Chicks&quot; 8 true)
 	      (struct cd &quot;Home&quot; &quot;Dixie Chicks&quot; 9 true)))
@@ -18,8 +18,8 @@
 ; use two doseqs (String/format not as flexible as CL format)
 ; better way than wrapping cd in (seq cd)?
 (defn dump-db [db]
-  (doseq cd db
-    (doseq [key value] (seq cd) 
+  (doseq rec db
+    (doseq [key value] rec 
       (print (format &quot;%10s: %s\n&quot; (name key) value)))
     (println)))
 
@@ -77,21 +77,26 @@
 ; (filter (cddb/artist-selector &quot;Dixie Chicks&quot;) (cddb/init-db))
 
 ; more general (but allows &quot;bad&quot; keys to be specified)
+; simpler with 'every but written this way for demo purposes
 (defn where [criteria]
-  (fn [cd]
+  (fn [m]
     (loop [criteria criteria] 
       (let [[k,v] (first criteria)]
 	(or (not k)
-	    (and (= (k cd) v) (recur (rest criteria))))))))
-
-; in Clojure it is idiomatic for the functional argument to come first
-(defn update [criteria db updates]
-  (map 
-   (fn [cd] 
-     (if (criteria cd)
-       (merge cd updates)
-       cd))
-   db))
+	    (and (= (k m) v) (recur (rest criteria))))))))
+
+; use a built in seq function 
+(defn simpler-where [criteria]
+  (fn [m]
+    (every? (fn [[k v]] (= (k m) v)) criteria)))
+
+; RH recommends putting db first here for alter/commute purposes
+; into lets us generalize for different collections
+(defn update [db criteria updates]
+  (into (empty db) 
+   (map (fn [m] 
+	  (if (criteria m) (merge m updates) m))
+	db)))
   
 (defmacro backwards [expr] (reverse expr))
 </diff>
      <filename>pcl/chap_03/chap_03.clj</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>fd6d831ba41d46a82bd3804987dd545d4442895d</id>
    </parent>
  </parents>
  <author>
    <name>Stuart Halloway</name>
    <email>stu@thinkrelevance.com</email>
  </author>
  <url>http://github.com/stuarthalloway/practical-cl-clojure/commit/2423320922c368bf7ab1f732aeed7ae06580b956</url>
  <id>2423320922c368bf7ab1f732aeed7ae06580b956</id>
  <committed-date>2008-09-17T10:11:23-07:00</committed-date>
  <authored-date>2008-09-17T10:11:23-07:00</authored-date>
  <message>updates per Rich Hickey's suggestions</message>
  <tree>f45737355db031cb73185ee11e62f18fea150e39</tree>
  <committer>
    <name>Stuart Halloway</name>
    <email>stu@thinkrelevance.com</email>
  </committer>
</commit>
