On 21/11/13 13:19, John D. Hume wrote:

If you want to demonstrate STM with the deposit-withdraw-transfer example, you definitely need a ref for each account.

I'd suggest an atom for the account-num->balance-ref map ("the bank") and an atom for the account-num-generator, but you say coordination is necessary for opening and closing accounts. What coordination do you have in mind?



exactly my point! thank you...

I finally settled to an atom (the entire bank) that holds a map from string ids to a ref containing the actual customer-account map. Sorry, by coordination, I meant atoms or refs. It needs to be synchronous because we may open an account and deposit immediately. am I not thinking correctly?

also, people complained about me doing this because I'm altering a single identity:

(defn deposit!
[account amount]
 (dosync
   (alter account credit amount)))

whereas this is fine:

(defn- transfer1
 [amount from to]
(dosync
   (alter to  credit amount)
   (alter from debit amount)))

but I can't have it both ways! if accounts are refs then a simple deposit or withdraw must happen in a transaction...


Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to