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 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-offers (:all-offers args)
   streams (:streams offer)]
   (dosync
 (cond
   (empty? @unique-offers)
   ((logger/log map @unique-offers)
 (alter unique-offers assoc offer-value streams))
   :else (logger/log  error)

 unique-offer is ref for map which is empty so condition (empty?
 @unique-offers) is true.
 Statement (alter unique-offers assoc offer-value streams) never changes
 unique-offers map.
 If I remove cond from function it works fine (The function has only dosyn
 and alter).

 What am I doing wrong?

 Thanks

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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 
odysso...@gmail.com wrote:

 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 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-offers (:all-offers args)
streams (:streams offer)]
   (dosync
 (cond
   (empty? @unique-offers)
   ((logger/log map @unique-offers)
 (alter unique-offers assoc offer-value streams))
   :else (logger/log  error)

 unique-offer is ref for map which is empty so condition (empty?
 @unique-offers) is true.
 Statement (alter unique-offers assoc offer-value streams) never changes
 unique-offers map.
 If I remove cond from function it works fine (The function has only dosyn
 and alter).

 What am I doing wrong?

 Thanks

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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 is old value but all-offers is
new value?

Thanks



On Tue, Apr 26, 2011 at 9:55 PM, Jonathan Fischer Friberg 
odysso...@gmail.com wrote:

 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 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-offers (:all-offers args)
streams (:streams offer)]
   (dosync
 (cond
   (empty? @unique-offers)
   ((logger/log map @unique-offers)
 (alter unique-offers assoc offer-value streams))
   :else (logger/log  error)

 unique-offer is ref for map which is empty so condition (empty?
 @unique-offers) is true.
 Statement (alter unique-offers assoc offer-value streams) never changes
 unique-offers map.
 If I remove cond from function it works fine (The function has only dosyn
 and alter).

 What am I doing wrong?

 Thanks

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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 zlatko.jo...@gmail.comwrote:

 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 is old value but all-offers is
 new value?

 Thanks



 On Tue, Apr 26, 2011 at 9:55 PM, Jonathan Fischer Friberg 
 odysso...@gmail.com wrote:

 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 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-offers (:all-offers args)
streams (:streams offer)]
   (dosync
 (cond
   (empty? @unique-offers)
   ((logger/log map @unique-offers)
 (alter unique-offers assoc offer-value streams))
   :else (logger/log  error)

 unique-offer is ref for map which is empty so condition (empty?
 @unique-offers) is true.
 Statement (alter unique-offers assoc offer-value streams) never changes
 unique-offers map.
 If I remove cond from function it works fine (The function has only dosyn
 and alter).

 What am I doing wrong?

 Thanks

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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 it posible that
one thread tests first condition (empty? @map1) and gets true
than another thread comits its transaction wich puts values in both maps.
Now first thread check second
condition (empty? @map2) which is false.



On Tue, Apr 26, 2011 at 10:17 PM, Jonathan Fischer Friberg 
odysso...@gmail.com wrote:

 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 zlatko.jo...@gmail.comwrote:

 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 is old value but all-offers is
 new value?

 Thanks



 On Tue, Apr 26, 2011 at 9:55 PM, Jonathan Fischer Friberg 
 odysso...@gmail.com wrote:

 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 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-offers (:all-offers args)
streams (:streams offer)]
   (dosync
 (cond
   (empty? @unique-offers)
   ((logger/log map @unique-offers)
 (alter unique-offers assoc offer-value streams))
   :else (logger/log  error)

 unique-offer is ref for map which is empty so condition (empty?
 @unique-offers) is true.
 Statement (alter unique-offers assoc offer-value streams) never changes
 unique-offers map.
 If I remove cond from function it works fine (The function has only
 dosyn and alter).

 What am I doing wrong?

 Thanks

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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 that particular transaction, and retries. All of this
happens automatically, so you wont have to worry.

On Tue, Apr 26, 2011 at 10:33 PM, Zlatko Josic zlatko.jo...@gmail.comwrote:

 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 it posible that
 one thread tests first condition (empty? @map1) and gets true
 than another thread comits its transaction wich puts values in both maps.
 Now first thread check second
 condition (empty? @map2) which is false.



 On Tue, Apr 26, 2011 at 10:17 PM, Jonathan Fischer Friberg 
 odysso...@gmail.com wrote:

 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 zlatko.jo...@gmail.comwrote:

 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 is old value but all-offers is
 new value?

 Thanks



 On Tue, Apr 26, 2011 at 9:55 PM, Jonathan Fischer Friberg 
 odysso...@gmail.com wrote:

 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 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-offers (:all-offers args)
streams (:streams offer)]
   (dosync
 (cond
   (empty? @unique-offers)
   ((logger/log map @unique-offers)
 (alter unique-offers assoc offer-value streams))
   :else (logger/log  error)

 unique-offer is ref for map which is empty so condition (empty?
 @unique-offers) is true.
 Statement (alter unique-offers assoc offer-value streams) never changes
 unique-offers map.
 If I remove cond from function it works fine (The function has only
 dosyn and alter).

 What am I doing wrong?

 Thanks

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, 

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)
 .
 
 
 Suppose the process method is called from many threads. Is it posible that 
 one thread tests first condition (empty? @map1) and gets true
 than another thread comits its transaction wich puts values in both maps. Now 
 first thread check second
 condition (empty? @map2) which is false.

Yes. This is perfectly possible. You have to wrap the whole cond in a dosync. 
Otherwise it is not guaranteed that you see consistent values of map1 and map2.

Sincerely
Meikel

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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 #'and expression is theoretically
possible. For this reason, #'deref/@ and #'alter are best kept in the
same transaction in this situation.

 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 that particular transaction, and retries. All of this
 happens automatically, so you wont have to worry.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


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 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 theoretically
 possible. For this reason, #'deref/@ and #'alter are best kept in the
 same transaction in this situation.

  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 that particular transaction, and retries. All of
 this
  happens automatically, so you wont have to worry.

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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)
  all-offers (:all-offers args)
  streams (:streams offer)]
  (dosync
(cond
  (empty? @unique-offers)
  ((logger/log map @unique-offers)
(alter unique-offers assoc offer-value streams))
  :else (logger/log  error)


On Tue, Apr 26, 2011 at 11:38 PM, Jonathan Fischer Friberg 
odysso...@gmail.com wrote:

 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 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 theoretically
 possible. For this reason, #'deref/@ and #'alter are best kept in the
 same transaction in this situation.

  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 that particular transaction, and retries. All of
 this
  happens automatically, so you wont have to worry.

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 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 post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

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 (:out-queue args)
   unique-offers (:unique-offers args)
   all-offers (:all-offers args)
   streams (:streams offer)]  
   (dosync  
 (cond 
   (empty? @unique-offers)
   ((logger/log map @unique-offers) ; — Add do here after first (
 (alter unique-offers assoc offer-value streams))
   :else (logger/log  error)

Are you sure, that there is not exception thrown, which is eaten somehow? I 
suspect that the logger/log returns nil, which causes a NPE without updating 
the ref. Try adding a do after the first ( in the marked line above.

Sincerely
Meikel

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en