>
> But surely in this case you could do:
>
> (defn print-info []
>   (let [[src dst] (dosync [...@source-account @dest-account])]
>     (println src)
>     (println dst)))
>
> or maybe:
>
> (defn print-info []
>   (let [[src dst] (dosync
>                     (ensure source-account)
>                     (ensure dest-account)
>                     [...@source-account @dest-account])]
>     (println src)
>     (println dst)))
>
> I suspect the ensures are necessary, but I would appreciate it if
> someone could explain why they are (or are not) necessary in this
> case.

As far as I know, dosync guarantees that the derefs are consistent
with each other. That is, no other transaction can affect the return
value of the deref while the transaction is running. However, deref
doesn't guarantee that the values read are still current when the
transaction finishes. Some other transaction might have been committed
first. If you absolutely need the most recent values, not just
consistent ones, you need to use ensure.

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