Is this the common way to do it?
(def sister (assoc brother :name "Cindy"))
If you want to change the value of one key in a map, yes. (In this
example it looks weird, of course.)
If you want to create a new map by taking only some values from
another map:
user=> (def sister (assoc (select-keys brother
[:father :mother]) :name "Mandy"))
#'user/sister
user=> sister
{:name "Mandy", :mother "Mary", :father "John"}
Reading up more on structs, it seems they have base keys that can't be
dissoc. Is that the main difference then between it and a hash?
Yes. The base keys are reserved as an array, which provides a slight
performance enhancement in some situations (no tree-walking). If you
have no need for that tiny performance enhancement, you can ignore
struct-maps altogether.
--
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
To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or
reply to this email with the words "REMOVE ME" as the subject.