Hi,
I've probably been staring at this for too long to see, what I am doing
wrong.
I have a Ref which contains a vector similar to the following
(def data
[{:a {:b 1 :c 0}}
{:a {:d 1 :g 0}}
{:a {:e 1 :h 0}}
{:a {:f 1 :i 0}}])
There is a second ref, which is similar but without the :a-nesting.
Between those I move values by decreasing the int for a key in one ref and
increasing it in the other.
As long as I i use a function like the following, everything works fine:
(defn upd1 [d id k v]
(if-not (get-in d [id :a k])
(assoc-in d [id :a k] 1)
(update-in d [id :a k] inc)))
But when I use something like this I manage to get my Refs into
inconsistent state, where the overall sum of all ints is not constant
anymore.
(defn upd2 [d id k v]
(let [keyseq [id :a k]]
(update-in d
keyseq
#(inc (get-in % keyseq 0)))))
(Actually, this is a simplified example. I'll try to reproduce with this
simpler setup.)
Can anyone see an obvious reason why this fails? I am on Clojure 1.5.1.
Thanks,
stefan
--
--
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/groups/opt_out.