Re: Cheap defrecord transformation

2012-04-25 Thread Meikel Brandmeyer (kotarak)
Hi, your comparison is not fair. The map example merely assoc's a new value, while in the record case you create a complete fresh value with a different type. Here some more comparisons: user=> (defrecord Foo [a b]) user.Foo user=> (defrecord Bar [a b c]) user.Bar user=> (let [x (->Foo 10 20)]

Re: Cheap defrecord transformation

2012-04-25 Thread Lars Nilsson
On Wed, Apr 25, 2012 at 10:30 AM, Shantanu Kumar wrote: > user=> (let [x (Foo. 10 20)] (time (Bar. (:a x) (:b x) 30))) > "Elapsed time: 0.686 msecs" > #user.Bar{:a 10, :b 20, :c 30} > > Whereas, doing the same with a map is very cheap: > > user=> (let [x {:a 10 :b 20}] (time (assoc x :c 30))) > "E

Re: Cheap defrecord transformation

2012-04-25 Thread Shantanu Kumar
> user=> (map->B (merge (A. 1 2) {:c 1})) > #user.B{:a 1, :b 2, :c 1} Pretty cool – thanks! Didn't know about map-> Shantanu -- 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 post

Re: Cheap defrecord transformation

2012-04-25 Thread Ambrose Bonnaire-Sergeant
On Wed, Apr 25, 2012 at 10:30 PM, Shantanu Kumar wrote: > 2. It is quite verbose to construct a Bar from a Foo. Knowing that > there is an overlap of attributes, is there a less verbose way to do > it? > > Have you tried this? user=> (map->B (merge (A. 1 2) {:c 1})) #user.B{:a 1, :b 2, :c 1} Tha

Cheap defrecord transformation

2012-04-25 Thread Shantanu Kumar
Hi, I have a scenario where I have two records: (defrecord Foo [a b]) (defrecord Bar [a b c]) You will notice Bar has only an attribute more than Foo. Both Foo and Bar are data abstractions where Foo is a subset of Bar. Now, when I try to construct a Bar from an existing Foo instance, I get thi