This may be really basic.  So much so that it's hard to find on the
internet, but is there something like a copy constructor in clojure,
where I can copy everything in a structure except one or two keys?
Maybe something like struct-map, but fills in the other variables not
supplied by another data structure.


There's no need for copying with Clojure's native data structures.

Clojure data structures are persistent: for example, if you dissoc a key from a map, you get a new map with the same contents as the original minus the dissociated key. The original map is unchanged. The new map safely shares structure with the original.

This is both efficient and safe.

E.g.,

user=> (def aaa {:foo 1 :bar 2 :baz 3})
#'user/aaa
user=> (dissoc aaa :foo :baz)
{:bar 2}
user=> aaa
{:foo 1, :bar 2, :baz 3}


If you want to draw values from two maps, use merge:

user=> (merge {:foo 0 :bar 0 :baz 0} (dissoc aaa :foo :baz))
{:foo 0, :bar 2, :baz 0}

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

Reply via email to