Hi,all

      I am new to clojure.  Now I hava a problem about read
transcation.
      Suppose now I write some code about bank transfer. So this is
the source-account and destination-account

//The code
(def source-account (ref 1000))
(def dest-account (ref 0))

    And I have a function to do the account transfer.
//The code
(defn take-money [account num]
  (- account num))

(defn despoite [account num]
  (+ account num))

(defn transfer-money [num]
  (dosync (alter source-account take-money num)
          (alter dest-account despoite num)))

    And I have a another function to print the source account and dest
acoount information.
//The code
(defn print-info []
  (do
    (println @source-account)
    (println @dest-account)))

   Suppose the transfer-money and print-info are run in different
thread. With the current Clojure STM, is it possible that print-info
prints the old source-account information and modified dest-account
information?  Do I need to add a dosync to the print-info function? I
read the Programming Clojure. It says do not have side-effect on a
transaction. If I add dosync to the print-info, do I need to use agent
to print the info?  Hope somebody can help me.

Thank.
Jack


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

Reply via email to