;; ;; A simple banking system as an example to illustrate refs in Clojure ;; (def account-a (ref 100)) (def account-b (ref 100)) (defn transfer! [amount from to] (dosync (if (>= (- @from amount) 0) (do (alter from - amount) (alter to + amount))))) (defn deposit! [amount account] (dosync (alter account + amount))) (defn withdraw! [amount account] (dosync (if (>= (- @account amount) 0) (alter account - amount)))) (defn show-balance [account] (str "Balance: " @account))