Re: another n00b defrecord combination question

2012-12-16 Thread Leif
Hi, Ray. When you are doing things that have a relational algebra feel to them (joins, etc.), you might want to consider the fns in the clojure.set namespace. E.g.: ;; convert vectors of records to sets, then: > (clojure.set/join (clojure.set/rename items {:id :iid :name :iname}) ; to p

Re: another n00b defrecord combination question

2012-12-16 Thread Ray
Hilarious - I am so conditioned already to have everything in a list :) Thanks for your patient explanation. Merry xmas. ray Ray On Sunday 16 December 2012 at 22:20, Benjamin R. Haskell wrote: > On Sun, 16 Dec 2012, mond wrote: > > > One small thing Ben... when I try to use the final formu

Re: another n00b defrecord combination question

2012-12-16 Thread Benjamin R. Haskell
On Sun, 16 Dec 2012, mond wrote: One small thing Ben... when I try to use the final formulation I receive an error: (def joined-products (map product-with-item products)) user=> (joined-products) ClassCastException clojure.lang.LazySeq cannot be cast to clojure.lang.IFn   user/eval241 (NO_SOUR

Re: another n00b defrecord combination question

2012-12-16 Thread mond
One small thing Ben... when I try to use the final formulation I receive an error: (def joined-products (map product-with-item products)) user=> (joined-products) ClassCastException clojure.lang.LazySeq cannot be cast to clojure.lang.IFn user/eval241 (NO_SOURCE_FILE:9) Any ideas? Thanks in a

Re: another n00b defrecord combination question

2012-12-16 Thread mond
Great stuff Ben. Thanks. ray On Saturday, December 15, 2012 10:54:42 PM UTC+1, Benjamin R. Haskell wrote: > > On Sat, 15 Dec 2012, mond wrote: > > > Thanks for picking up the cudgels Ben! > > Ha. It's nice to have reached a point where I feel at-all confident > with any of this... happy to he

Re: another n00b defrecord combination question

2012-12-15 Thread Benjamin R. Haskell
On Sat, 15 Dec 2012, mond wrote: Thanks for picking up the cudgels Ben! Ha. It's nice to have reached a point where I feel at-all confident with any of this... happy to help. To be honest I am struggling to repeat your advice in the REPL.  In any case, I decided to change the data struct

Re: another n00b defrecord combination question

2012-12-15 Thread mond
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

Re: another n00b defrecord combination question

2012-12-15 Thread Benjamin R. Haskell
(responses inline) On Sat, 15 Dec 2012, mond wrote: I have defined these types of records for modelling a simple shopping cart: ; An item in the cart (defrecord Item [id name product quantity purchased]) ; The product that relates to the item in the cart (defrecord Product [id name descriptio

Re: another n00b defrecord combination question

2012-12-15 Thread Benjamin R. Haskell
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))

Re: another n00b defrecord combination question

2012-12-15 Thread mond
OK - I have it now: (map (fn [item product] (= (:product item (:id product))) [(:id item) (:description product)]) items products) This feels OK to me but if anyone has a nicer / more idiomatic solution, I will be happy to take feedback. ray On Saturday, December 15, 2012 7:08:21 PM UTC+1, mo

Re: another n00b defrecord combination question

2012-12-15 Thread mond
I think I am close to answering this myself (which is always nice!) I have done the necessary joins with map and I can return a product description user=> (map (fn [item product] (= (:product item (:id product))) (:description product)) items products) ("Men's Leather Slip on Brogues" "CK Y Fro