Re: cond in dosync problem

2011-04-26 Thread Zlatko Josic
You where right. return of logger/log was nil. Thank you very much. On Wed, Apr 27, 2011 at 1:04 AM, Meikel Brandmeyer wrote: > 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)? > > > > > > (def

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)) >

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 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 > wrote: > > No, that isn't possible.http://clojure

Re: cond in dosync problem

2011-04-26 Thread Daniel Werner
On Apr 26, 10:52 pm, Jonathan Fischer Friberg 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 #'and expression is the

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 v

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 th

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. Is

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 wrote: > I have given

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 i

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 < ody

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 wrote: > Hi, > > I use cond in dosync but it doesn't work. Here is

cond in dosync problem

2011-04-26 Thread Zlatko Josic
Hi, I use cond in dosync but it doesn't work. Here is a function code: (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) all-of