On Oct 15, 8:38 pm, Rich Hickey <[EMAIL PROTECTED]> wrote:
> On Oct 15, 8:14 pm, Michel Salim <[EMAIL PROTECTED]> wrote:
>
> > The documentation for assoc (both using find-doc and on the website)
> > stipulates that the index must be <= (count col). This is incorrect,
> > though, since index ranges from [0, (count col)) ?
>
> No, the docs are correct - you can assoc one past the end, it's
> equivalent to conj:
>
> (assoc [] 0 :fred)
> -> [:fred]
>
Ah yes, that works. Weird, I had an earlier example that failed, but I
could not reproduce it -- must have made a mistake somewhere, as I was
trying to figure out how to modify references at the same time.
It would be nice to have the two use cases documented -- actually,
just discovered you can keep extending it too:
(assoc [] 0 :a 1 :b 2 :c)
Presumably the left-to-right extension of the vector is part of
assoc's semantics.
Thanks,
--
Michel Salim
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---