You need to provide a key and a value. (assoc book :authors (conj ...
LP > Thanks James, > > But how do I use assoc with it > > I tried this : > > (defn add-author [book new-author] > (assoc book (conj (book :authors) new-author))) > > but then I see this message : > > ArityException Wrong number of args (2) passed to: core$assoc > clojure.lang.AFn.throwArity (AFn.java:437) > > Roelof > > > Op woensdag 29 oktober 2014 12:08:35 UTC+1 schreef James Reeves: > > > On 29 October 2014 11:01, Roelof Wobben <rwo...@hotmail.com <javascript:>> > > wrote: > >> > >> For a exercise I have to add something to the end of a existing map. > >> > >> So I thought this would work : > >> > >> (defn add-author [book new-author] > >> (assoc book (conj :authors new-author))) > >> > > > > Take a look at that conj expression on its own: > > > > (conj :authors new-author) > > > > You're trying to conjoin "new-author" onto the keyword :authors, but > > keywords aren't collections. That's what the error means. It's saying that > > it expected a collection, but you've supplied a keyword instead. > > > > What you want is: > > > > (conj (get book :authors) new-author) > > > > Which can also be written: > > > > (conj (book :authors) new-author) > > > > (conj (:authors book) new-author) > > > > These two expressions are shortcuts for the above "get" function. They > > work because maps and keywords can act as functions. > > > > - James > > > > -- > 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 > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Luc Prefontaine<lprefonta...@softaddicts.ca> sent by ibisMail! -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.