我想MAX_OPERATIONS
从一个帐户向另一个帐户进行多次 ( ) 次汇款。帐户作为参考存储在哈希映射调用程序中my-map
(int account-id,double balance)。
汇款从哈希映射中获取“随机索引”并将其传递account-from
给transfer
。account-destination
并且amount
都应该修复。
不幸的是我不能让它工作。
(defn transfer [from-account to-account amount]
(dosync
(if (> amount @from-account)
(throw (Exception. "Not enough money")))
(alter from-account - amount)
(alter to-account + amount)))
(defn transfer-all []
(dotimes [MAX_OPERATIONS]
(transfer (get mymap (rand-int[MAX_ACCOUNT]) :account-id) account-destination amount)))