@Chas, update uses a function to perform the update. Think of it as being
like swap! and alter, but for persistent associative structures. So you can
write something like: (update {:foo 0} :foo inc) to increment the value of
:foo.
update is to update-in as assoc is to assoc-in.
If you write a lot of code that uses swap! or alter, the absence of
something similar for persistent associative structures becomes more
conspicuous. And the fact that such a function (update-in) exists for
nested associative structures makes its absence even odder.
@Stuart, yes I'd estimate this has come up on the lists approx. 3 times per
year over the past couple of years.
Unfortunately, the word "update" is sufficiently common that it makes it
difficult to search the groups for this discussion topic.
But I was able to find a discussion of this as far back as April 2009:
http://groups.google.com/group/clojure/browse_thread/thread/4eb34e04a8d4fe6b/3017a1502a3a04a8
I have seen people define update in their own code, but more often than not
I see people do something like
(update-in map [k] f)
because they don't want to bother defining update themselves. I personally
think it would be more elegant to put the implied "update" function directly
into the core.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
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