Re: cond in dosync problem

2011-04-26 Thread Jonathan Fischer Friberg
I don't know. However, given the situation I think (cond (empty? @unique-offers) (dosync ... alter ...) :else (logger/log error)) is better, since the change is more isolated. On Tue, Apr 26, 2011 at 9:45 PM, Zlatko Josic zlatko.jo...@gmail.comwrote: Hi, I use cond in dosync but it

Re: cond in dosync problem

2011-04-26 Thread Jonathan Fischer Friberg
On a closer look: ((logger/log map @unique-offers) (alter unique-offers assoc offer-value streams)) should probably be (do (logger/log map @unique-offers) (alter unique-offers assoc offer-value streams)) On Tue, Apr 26, 2011 at 9:55 PM, Jonathan Fischer Friberg

Re: cond in dosync problem

2011-04-26 Thread Zlatko Josic
I have given only part of function. I have condition like this : (cond (and (empty? @unique-offers) (empty? @all-offers)) I change in dosync both unique-offers and all-offers. If I use your suggestion (empty? @unique-offers) (dosync ... alter ...) Can I get in situation where unique-offers

Re: cond in dosync problem

2011-04-26 Thread Jonathan Fischer Friberg
The important part were that the dosync call is isolated. The condition doesn't really matter. By the way: wouldn't it be simpler to create a new map instead of altering unique-offers/all-offers? (this is also more idiomatic) On Tue, Apr 26, 2011 at 10:02 PM, Zlatko Josic

Re: cond in dosync problem

2011-04-26 Thread Zlatko Josic
Is this scenario posible : (def test-map (ref {})) (def test-map2 (ref {})) (defn process [map1 map2] (cond (and (empty? @map1) (empty? @map2)) (dosync ((alter map1 assoc key1 value1) (alter map2 assoc key2 value2) . Suppose the process method is called from many threads.

Re: cond in dosync problem

2011-04-26 Thread Jonathan Fischer Friberg
No, that isn't possible. http://clojure.org/refs Inside a transaction (a dosync call), values updated in another transaction wont be seen. This means that the first transaction wont see the change until it commits, at that moment it realizes that the ref that were altered was changed outside of

Re: cond in dosync problem

2011-04-26 Thread Meikel Brandmeyer
Hi, Am 26.04.2011 um 22:33 schrieb Zlatko Josic: Is this scenario posible : (def test-map (ref {})) (def test-map2 (ref {})) (defn process [map1 map2] (cond (and (empty? @map1) (empty? @map2)) (dosync ((alter map1 assoc key1 value1) (alter map2 assoc key2 value2)

Re: cond in dosync problem

2011-04-26 Thread Daniel Werner
On Apr 26, 10:52 pm, Jonathan Fischer Friberg odysso...@gmail.com wrote: No, that isn't possible.http://clojure.org/refs I disagree: In the example given, dereferencing happens outside the dosync block, thus outside of any transaction, so a race where map1 and map2 change midway through the

Re: cond in dosync problem

2011-04-26 Thread Jonathan Fischer Friberg
Yes, you're right, I'm wrong. :) The derefs must be in the dosync block. (which I somehow assumed, oh well) On Tue, Apr 26, 2011 at 11:17 PM, Daniel Werner daniel.d.wer...@googlemail.com wrote: On Apr 26, 10:52 pm, Jonathan Fischer Friberg odysso...@gmail.com wrote: No, that isn't

Re: cond in dosync problem

2011-04-26 Thread Zlatko Josic
Any idea why changes in the function below does'nt work (see first post on this topic)? (defn process-request [offer args] (logger/log process called) (let [offer-value (Double/parseDouble (:offer offer)) out-queue (:out-queue args) unique-offers (:unique-offers args)

Re: cond in dosync problem

2011-04-26 Thread Meikel Brandmeyer
Hi, Am 27.04.2011 um 00:33 schrieb Zlatko Josic: Any idea why changes in the function below does'nt work (see first post on this topic)? (defn process-request [offer args] (logger/log process called) (let [offer-value (Double/parseDouble (:offer offer)) out-queue