Skip to content

Instantly share code, notes, and snippets.

@stoyle
Created August 29, 2010 15:15
Show Gist options
  • Save stoyle/556368 to your computer and use it in GitHub Desktop.
Save stoyle/556368 to your computer and use it in GitHub Desktop.
(defn transfer [from-account to-account amount]
(dosync
(if (> amount @(:balance from-account))
(throw (new Exception "Not enough money!")))
(alter (:balance from-account) - amount)
(alter (:balance to-account) + amount)))
(defrecord Account [account-no balance])
(def account-a (Account. 1 (ref 1000)))
(def account-b (Account. 2 (ref 800)))
(transfer account-a account-b 300)
@(:balance account-a)
=> 700
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment