But I thought for a ref, all the "checking if an another thread has
changed the value behind my back" facility/logic is already there
(otherwise how can "dosync" and "alter" work, right?). So why not
using that?

I did send the question to Rich but not sure he will have time to
attend this. I am still learning Clojure and so far like it
(especially compared to the bad experience with Common Lisp), but my
perfectionist side pokes me sometimes.

On May 17, 6:42 pm, DAemon <forsakendae...@gmail.com> wrote:
> The reason that comes to mind most easily for me is that of deciding which
> notion of equality to use for 'the value of Ref hasn't changed'.
>
> Also, short of keeping a counter on the Ref of the number of times it's
> been changed, and comparing on that, there's no other way to tell that no
> other thread has changed the Ref, as far as I know. Although I could be
> wrong, *throws question to the Gods of clojure*
>
>
>
>
>
>
>
> On Fri, May 18, 2012 at 8:03 AM, Warren Lynn <wrn.l...@gmail.com> wrote:
> > Thanks and these are certainly workable solutions. But is there any
> > particular reason why with commute the update function is ALWAYS
> > called twice, even when no other thread changed the ref value at the
> > commit time? That is what bothers me.
>
> > On May 17, 5:46 pm, DAemon <forsakendae...@gmail.com> wrote:
> > > Would some of this difficulty be ameliorated by calling memoize on the
> > > function that you use? That way, if it's an expensive function, and the
> > > value hasn't changed, it's just looked up rather than recalculated.
>
> > > - DAemon
>
> > > On Fri, May 18, 2012 at 6:28 AM, Stuart Sierra
> > > <the.stuart.sie...@gmail.com>wrote:
>
> > > > I think the point with `commute` is to allow for more concurrency at
> > the
> > > > expense of more computation.
>
> > > > If you want assurance that your function is only called once, you can
> > use
> > > > `alter`.
>
> > > > Keep in mind that *any* code in a Ref transaction has the potential to
> > be
> > > > called more than once if there's a conflict.
>
> > > > All this doesn't mean that it's impossible to avoid the duplicate
> > > > computation on `commute`. The code to study would be here:
>
> > > >https://github.com/clojure/clojure/blob/8fda34e4c77cac079b711da59d5fe.
> > ..
>
> > > > -S
>
> > > >  --
> > > > 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 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 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

Reply via email to