On Jan 25, 2:29 pm, Meikel Brandmeyer <m...@kotka.de> wrote:
> Hi,
>
> Am 25.01.2009 um 20:00 schrieb Dmitri:
>
> > I ran into a situation where I needed to replace an element in a
> > collection at a specific position, I ended up writing the following:
>
> > (defn replace-at [coll pos value]
> >  "replaces an element in collection at pos with the value"
> >  (let [parts (split-at pos coll)]
> >    (concat (first parts) (cons value (rest (second parts))))))
>
> > I was wondering if there's a standard function to do this
>
> At least for vectors (and of course maps) you can use assoc-in.
>
> 1:1 user=> (assoc-in [1 2 3] [1] :x)
> [1 :x 3]
>

Or simply assoc:

(assoc [1 2 3] 1 :x)
[1 :x 3]

Rich
--~--~---------~--~----~------------~-------~--~----~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to