On Apr 5, 2009, at 3:11 PM, Hugh Winkler wrote:
From http://clojure.org/refs : "I/O and other activities with side-effects should be avoided in transactions, since transactions will be retried. The io! macro can be used to prevent the use of an impure function in a transaction."
Isn't it OK to do I/O in a transaction as long as doing the operation multiple times has the same effect as doing it once (i.e. it's idempotent)?
I suspect that Rich used the word "should" there rather than "must" as a nod to cases like those you described. Any activities with side- effects whose correctness will not be harmed if they are repeated (potentially many times) are OK to include in a transaction.
Ultimately program correctness is up to you. The purpose of the admonition is to put you on notice that the probability of retries for code in transactions (over time) is approximately 100%. Any side effects you include in them need to be carefully considered and will work properly only if they are truly safe if repeated.
--Steve
smime.p7s
Description: S/MIME cryptographic signature