Is there a shorter way to do this?
See my earlier message. dissoc and assoc will do what you want.
(def brother {:name "Gary" :address "..." :mother "Mary" :father
"John"})
(def sister (assoc brother :name "Cindy"))
user=> sister
{:name "Cindy", :address "...", :mother "Mary", :father "John"}
While I'm on the subject, what is the difference between a structure
and a hash? Are there performance implications? Why wouldn't I just
use a hash if structs can hold new values anyway? When should I use
one over the other?
A struct-map is strictly a performance optimization, with one
additional constraint (that the required keys cannot be removed from
the struct: if you try, you'll get an error).
In every other respect it behaves just like any other map.
There are only two reasons to use struct-maps: if you've profiled and
need the tiny performance improvement (struct-maps store their
required keys in an internal array, which is sometimes faster); or if
you feel that struct-maps offer some documentation advantage for your
code.
struct-maps are not Clojure's equivalent of objects. Use maps unless
you have a clear reason to do otherwise.
--
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
To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or
reply to this email with the words "REMOVE ME" as the subject.