From dce7ffebf9588f2b58fb04b7c4b270ae42ee29c6 Mon Sep 17 00:00:00 2001 From: Felix Martin Date: Tue, 29 Dec 2020 14:00:47 -0500 Subject: [PATCH] Answer till 3.45 --- ex-2_73-76.scm | 6 +++++ ex-3_38-xx.scm => ex-3_38-45.scm | 39 ++++++++++++++++++++++++++++---- ex-3_46-xx.scm | 8 +++++++ 3 files changed, 49 insertions(+), 4 deletions(-) rename ex-3_38-xx.scm => ex-3_38-45.scm (53%) create mode 100644 ex-3_46-xx.scm diff --git a/ex-2_73-76.scm b/ex-2_73-76.scm index b14dc24..b2c1107 100644 --- a/ex-2_73-76.scm +++ b/ex-2_73-76.scm @@ -2,6 +2,12 @@ (newline) (display "ex-2.73 - deriv data-directed") (newline) +(define *op-table* (make-hash-table)) +(define (put op type proc) + (hash-table/put! *op-table* (list op type) proc)) +(define (get op type) + (hash-table/get *op-table* (list op type) #f)) + (display "a. - see comments\n") ; a. diff --git a/ex-3_38-xx.scm b/ex-3_38-45.scm similarity index 53% rename from ex-3_38-xx.scm rename to ex-3_38-45.scm index 5c23274..7435a60 100644 --- a/ex-3_38-xx.scm +++ b/ex-3_38-45.scm @@ -1,5 +1,3 @@ -(load "util.scm") - (display "\nex-3.38\n") (display "[answered]\n") @@ -63,8 +61,8 @@ ; Ben's concern does not apply. Say, we have a withdraw and a balance check. ; Depending on the order of execution the balance check would show the balance -; before or after the withdraw. This behavior is expectected and would not be -; migated by serializing balance. +; before or after the withdraw. This behavior is expected and would not be +; avoided by serializing balance. (display "\nex-3.42\n") (display "[answered]\n") @@ -73,6 +71,39 @@ ; model of how the serializer works, yet. (display "\nex-3.43\n") +(display "[answered]\n") + +; A swap of account balances maintains each individual balance. Hence, only the +; order of $10, $20, $30 can change and not the value. + +; a b c +; $10 $20 $30 (swap a b = 10) (swap a c = 20) +; $20 $10 $30 +; $40 $10 $10 + +; The sum of balances will be preserved because the exchange procedure deposits +; what it withdraws. That works because it calculates `difference` before doing +; the transactions. + +; If the individual transactions would not be serialized we could run into a +; situation where (swap a c) overrides a to be $30, for example, as we have +; seen in previous exercises. (display "\nex-3.44\n") +(display "[answered]\n") + +; Louis Reasoner is wrong. Assuming the balance on from-account is high enough +; transfer is going to work. The essential difference is that executing a list +; of transactions of absolute amounts is commutative. Exchange, on the other, +; is not commutative. On exchange has to finish before another one and the +; order matters. + +(display "\nex-3.45\n") +(display "[answered]\n") + +; When serialized-exchange is call it tries to serialize the deposit and +; withdraw calls that are already serialized by the same serializer. That would +; result in a deadlock because because the outer serialized procedure would +; have to call the inner serialized procedure and they cannot be executed at +; the same time because they are serialized by the same serializer. diff --git a/ex-3_46-xx.scm b/ex-3_46-xx.scm new file mode 100644 index 0000000..ca9aac5 --- /dev/null +++ b/ex-3_46-xx.scm @@ -0,0 +1,8 @@ +(load "util.scm") + +(display "\nex-3.46\n") + +(display "\nex-3.47\n") + +(display "\nex-3.48\n") +