On Jan 21, 2013 3:28 PM, "Jim - FooBar();" <jimpi...@gmail.com> wrote:
> ...or you can go all the way, skipping reset! completely:
>
> (swap! game-objects (fn [objects] (reduce-kv #(assoc % %2 (update-object %3)) {} objects) ))
Which also has the benefit of being safe, unlike any reset!-based update.
--
Stephen Compall
If anyone in the MSA is online, you should watch this flythrough.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@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 clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
It's worth knowing that the "moment" is implemented via a compare-and-set, and if the value has been changed (by another thread), the fn you passed to swap! will be called again with the atom's new value.
> Can anyone explain the relationship between swap! and reset! ?swap! is for "CAS"
On Sat, Jun 29, 2013 at 5:07 PM, Brandon Bloom <brandon...@gmail.com> wrote:
> Can anyone explain the relationship between swap! and reset! ?swap! is for "CAS"How so? No comparison is done (unless it's done in the supplied function, which is entirely up to the user of swap!). There's a separate compare-and-set! function for atoms.
public Object swap(IFn f) {for(; ;){Object v = deref();Object newv = f.invoke(v);validate(newv);if(state.compareAndSet(v, newv)){notifyWatches(v, newv);return newv;}}}
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@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.
Who said swap *was* CAS, rather than was implemented *in terms of* CAS? In any event, your claim that "no comparison is done unless it's done in the supplied function" is just plain wrong. Comparison *is* done, outside that function, to make sure the atom wasn't changed by another thread while the function was executing.
Or just look at the source for clojure.lang.Atom.swap():
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@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 a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/PBiSzidSIVM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.
On Sat, Jun 29, 2013 at 6:06 PM, Cedric Greevey <cgre...@gmail.com> wrote:
Who said swap *was* CAS, rather than was implemented *in terms of* CAS? In any event, your claim that "no comparison is done unless it's done in the supplied function" is just plain wrong. Comparison *is* done, outside that function, to make sure the atom wasn't changed by another thread while the function was executing.
"swap! is for "CAS""