Thanks for picking up the cudgels Ben!

To be honest I am struggling to repeat your advice in the REPL.  In any 
case, I decided to change the data structures in line with your advice and 
put the IDs into maps rather than the records.

(defrecord Item [name product quantity purchased])

(defrecord Product [name description prices])

(defrecord Price [price tax currency])

(def items [ {:id 1 :item (->Item "Brogues" "P-123" 1 true)}
             {:id 2 :item (->Item "Underpants" "P-345" 2 false)}
             {:id 3 :item (->Item "Shirt" "P-678" 1 true)} ])

(def carts [ (->Cart "Birthday" (first items))
             (->Cart "Xmas" (rest items)) ])

(def products [ {:id "P-1231" :product (->Product "Table" "Coffee Table" 
(->Price 375 21 "EURO"))}
                {:id "P-3451" :product (->Product "Chairs" "Set of Four(4) 
chairs" (->Price 200 21 "EURO"))}
                {:id "P-123" :product (->Product "Brogues" "Men's Leather 
Slip on Brogues" (->Price 93.00 21 "EURO"))}
                {:id "P-345" :product (->Product "Underpants" "CK Y Fronts" 
(->Price 23.50 21 "EURO"))}
                {:id "P-678" :product (->Product "Shirt" "Slim Fit White 
Vest Shirt" (->Price 45.99 21 "EURO"))}
                {:id "P-6781" :product (->Product "TableCloth" "Classic red 
and white checks 2m x 2m" (->Price 17.99 21 "EURO"))} ])

Do you think the zipmap is still the way to go (to resolve the 'foreign 
key' or could there be an easier way? I guess the fact that only items have 
to zipmapped is one advantage.

Thanks for your support

ray


On Saturday, December 15, 2012 7:53:32 PM UTC+1, Benjamin R. Haskell wrote:
>
> On Sat, 15 Dec 2012, Benjamin R. Haskell wrote: 
>
> > Or if you really want a list, you need to quote it: 
> > 
> > (map (fn [item product] '(:id item :description product)) items 
> products) 
>
> Oops, wrong.  Rather, you would want clojure.core/list: 
>
> (map (fn [item product] (list :id item :description product)) items 
> products) 
>
> -- 
> Best, 
> Ben 
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to