On Jun 18, 5:23 pm, "Stephen C. Gilardi" <squee...@mac.com> wrote:
> On Jun 18, 2009, at 1:25 PM, Adam Blinkinsop wrote:
>
> > Does ref-set not set the "in-transaction-value"? It looks like the
> > only difference is the signature, and that can't be right.
>
> Both set the in-transaction value. ref-set sets a specific value.
> alter runs a function to transform the previous in-transaction value
> to a new one.
>
> Clojure doesn't always offer only a minimal set of tools to work with
> its pieces. One could write ref-set in terms of alter, for example.
> The only practical difference would be a small additional cost in
> runtime.
>
Most important is what they convey to the reader. ref-set says "I'm
trashing the current value of the ref", while alter says "I'm
transforming the current value of the ref". You should never use ref-
set to do the latter. alter, swap!, and send all have the same pattern
of transformation and are preferred.
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
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
-~----------~----~----~----~------~----~------~--~---