On Nov 19, 12:01 am, samppi <[email protected]> wrote:
> Question: are the general mechanisms for accessing and setting fields
> their keywords and assoc respectively:
> (deftype Bar [a b c d e])
> (def b (Bar 1 2 3 4 5))
> (:c b)
> (def c (assoc b :e 2))
> Does (:c b) and (assoc b :e 2) take advantage of Bar's field
> information? Is it any faster than using an array map? Are there any
> equivalents to struct maps' accessor functions?
I've been wondering about this myself. I think you'd often want a
"persistent" types in the sense of the persistent datastructure.
You can use the ability to implement interfaces, specifically
automatic support for IPersistentMap:
ser=> (deftype Bar [a b] [clojure.lang.IPersistentMap])
#'user/Bar
user=> (assoc (Bar 1 2) :a 42)
#:Bar{:a 42, :b 2}
user=>
I have a question here, though: what is this?
ser=> (assoc (Bar 1 2) :c 42)
#:Bar{:a 1, :b 2, :c 42}
user=> #:Bar{:a 1, :b 2, :c 42}
Is it a "Bar" with field-speed access to :a and :b and map-speed
access to :c?
Also can I assume that
(assoc (Bar 1 2) :a 42)
#:Bar{:a 42, :b 2}
will share structure with the (Bar 1 2) and still has fast access
to :a? Is the assoc function using that :a is a field?
I guess I am just asking if the performance guarantees are those I
would expect of Clojure (i.e., "too fast" ;-))
/Karl
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en