]> git.rkrishnan.org Git - sicp.git/commitdiff
solution to 3.44
authorRamakrishnan Muthukrishnan <vu3rdd@gmail.com>
Mon, 13 Jun 2011 16:52:13 +0000 (22:22 +0530)
committerRamakrishnan Muthukrishnan <vu3rdd@gmail.com>
Mon, 13 Jun 2011 16:52:13 +0000 (22:22 +0530)
src/sicp/ex3_44.rkt [new file with mode: 0644]

diff --git a/src/sicp/ex3_44.rkt b/src/sicp/ex3_44.rkt
new file mode 100644 (file)
index 0000000..7484364
--- /dev/null
@@ -0,0 +1,19 @@
+#lang racket
+
+;; Consider the problem of transferring an amount from one account to
+;; another. Ben Bitdiddle claims that this can be accomplished with the
+;; following procedure, even if there are multiple people concurrently 
+;; transferring money among multiple accounts, using any account 
+;; mechanism that serializes deposit and withdrawal transactions, for 
+;; example, the version of make-account in the text above.
+
+(define (transfer from-account to-account amount)
+  ((from-account 'withdraw) amount)
+  ((to-account 'deposit) amount))
+
+#|
+
+Since withdraw and deposit themselves are 'atomic' (or rather 'safe')
+there is no problem with this routine. 
+
+|#
\ No newline at end of file