On 3/21/14, 5:44 AM, Andy Smith wrote:
Im also interested as to why the mutable state approach would be less
performant? In the single thread case the locks would be optimized out
right?
No locks are used when using atoms, only compare-and-swap (CAS)
operations. While CAS operations are fast you don't want to use them
unless you need to in a multi-threaded system. Clojure nor the JVM will
"optimize out" the use of them in a single-threaded case like this.
They are a very heavy approach when all you need is local mutation.
Clojure doesn't have local mutation out of the box.. it is very
opinionated on how state should be handled. The example solution posted
earlier in the thread is more indiciative of how state like this is
handled in clojure.
As pointed out earlier in the thread if you wanted/needed to have local
mutation you could use https://github.com/ztellman/proteus. In the vast
majority of cases this is unneeded.
-Ben
--
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
---
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 [email protected]
<mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.
--
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
---
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 [email protected].
For more options, visit https://groups.google.com/d/optout.