Hi Jan,
Thanks for your explanations.
I have no idea how I managed to completely misunderstand
clojure/atom for the past few years -- I suspect it's because I never
use clojure/STM, and as a result, I've never had an atom roll back on
me.
I've decided to switch to agents.
Thanks again
Hi t x and Jan,
what about performing the side effect part of the function adding a watch?
(They are no more in alpha with the upcoming 1.6.)
Cheers,
Luca
Il giorno lunedì 17 febbraio 2014 09:29:57 UTC+1, t x ha scritto:
Hi Jan,
Thanks for your explanations.
I have no idea how I
Hi John,
Your solution is perfectly valid and optimal for the problem I
described above.
Unfortunately, I forgot to mention an additional constraint: sometimes I do:
(let [ foo (:some-selector @data-atom) ]
(swap! data-atom update-in [:other-selector] ... ))
which the - doesn't quite
You can use a ref instead of an atom. And use dosync with multiple alter,
so everything is safely inside a transaction.
On Feb 16, 2014 2:04 PM, t x txrev...@gmail.com wrote:
Hi John,
Your solution is perfectly valid and optimal for the problem I
described above.
Unfortunately, I
I believe that's the STM approach, which has the advanrtage of:
* can synchronize across multiple pieces of data
but has the disadvantage of:
* work must be pure since it can be retried
* possibly less efficient due to possibility of retrying
In the example I posted above, I only need
I'm afraid your understanding of atom swap! operations is not quite correct
- update function must (or should) be pure as well.
See the
documentationhttp://clojuredocs.org/clojure_core/clojure.core/swap!for swap!,
update function could be potentially called multiple times if
there are more
Hi Jan,
You're right. I'm wrong.
I'm grateful you pointed this out -- this would have otherwise been
impossible to debug.
===
To everyone:
Why can swap! be retried? This confuses me -- to implement swap!, why can't we
* have a lock
* ensure that only one
Hi t x,
I think, that lock-free approach an it's semantics is more in line with
other Clojure reference types such as refs.
It also encourages you to only use pure functions for state transitions,
among other things, such as significant
performance benefits in comparison with lock based
Hi,
Consider the following block of code:
## Sample Code
(ns test)
(def some-atom (atom {:tag :language
:name Clojure
:better-than [scheme java ruby python]}))
(defn demo-func []
(swap! some-atom assoc-in [:name] Clojure 1.6)
(swap!
On Sat, Feb 15, 2014 at 6:04 PM, t x txrev...@gmail.com wrote:
(defn what-I-want []
(with-atom some-atom
assoc-in ...
assoc-in ...
update-in ...))
I often do something like this and don't find it too ugly:
(swap! my-atom #(- %
(assoc-in [:k] v)
10 matches
Mail list logo