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 this performance number:

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)))
"Elapsed time: 0.05 msecs"
{:c 30, :a 10, :b 20}

My questions are –
1. Is it possible to construct a Bar from an existing Foo where the
performance is close to assoc for map?
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?

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 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