(oops my earlier message isn't quite
right, here's the correct one)
You also need to clarify your intention: are you adding an author to a list of authors, or setting the single author? I suppose the first, but then you need to be clear on what the list of authors is. In idiomatic clojure you'll want it to be a vector of authors, so if an author is a map like {:name "Gerald J. Sussman"}, then :authors must be associated to a vector of maps. Also bear in mind that assoc is geared towards associative data structures such as maps, while conj is geared towards sequential data structures such as vectors. That being said, you can still use assoc on vectors (indices are the keys) and use conj on maps (with a vector in the form of [key value]), but that's polymorphism convenience, not idiomatic. In the end add to a new author, you need to do: (assoc book :authors (conj (get book :authors) new-author)) Which can also be made more idiomatic as already mentioned: (update-in book [:authors] assoc new-author) The twisted way of doing it would be: (conj book [:authors (conj (:authors book) new-author)]) Try this in a REPL: (def book {:title "zbook" :authors [{:name "James"}]}) (def new-author {:name "Joe"}) (assoc book :authors (conj (get book :authors) new-author)) (update-in book [:authors] conj new-author) (conj book [:authors (conj (:authors book) new-author)]) On 29/10/14 12:20, Roelof Wobben wrote:
-- |
- where do I think the wrong way Roelof Wobben
- Re: where do I think the wrong way Di Xu
- Re: where do I think the wrong way James Reeves
- Re: where do I think the wrong way Roelof Wobben
- Re: where do I think the wrong way Luc Prefontaine
- Re: where do I think the wrong way James Reeves
- Re: where do I think the wrong way François Rey
- Re: where do I think the wrong way François Rey
- Re: where do I think the wrong way François Rey
- Re: where do I think the wrong way Roelof Wobben
- Re: where do I think the wrong ... juan.facorro
- Re: where do I think the wrong way Benjamin VanRyseghem
- Re: where do I think the wrong way Henrik Lundahl
- Re: where do I think the wrong way Sven Richter