]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex3_38.rkt
Merge branch 'master' of github.com:vu3rdd/sicp
[sicp.git] / src / sicp / ex3_38.rkt
1 #lang racket
2
3 #|
4
5 Peter:  (set! balance (+ balance 10))
6 Paul:   (set! balance (- balance 20))
7 Mary:   (set! balance (- balance (/ balance 2)))
8
9 1.
10
11 a. Peter deposits $10
12 b. Paul withdraws $20
13 c. Mary withdraws half of balance.
14
15 100 + 10 - 20 = 90 -> 90/2 -> $45
16
17 2. 
18
19 a. Peter deposits $10
20 b. Mary withdraws half of balance.
21 c. Paul withdraws $20
22
23 100 + 10 -> 55 - 20 -> $35
24
25 3.
26
27 a. Paul withdraws $20
28 b. Peter deposits $10
29 c. Mary withdraws half of balance.
30
31 100 - 20 + 10 -> 110 /2 -> $55
32
33 4. 
34
35 a. Paul withdraws $20
36 b. Mary withdraws half of balance.
37 c. Peter deposits $10
38
39 100 - 20 => 80 / 2 => 40 + 10 => 50
40
41 5.
42
43 a. Mary withdraws half of balance.
44 b. Peter deposits $10
45 c. Paul withdraws $20
46
47 100 / 2 => 50 + 10 - 20 => 40
48
49 6.
50
51 a. Mary withdraws half of balance.
52 b. Paul withdraws $20
53 c. Peter deposits $10
54
55 100 / 2 => 50 - 20 + 10 => 40
56
57 |#
58
59 #|
60
61 Balance could take many values if the three transactions are allowed to
62 happen concurrently.
63
64 It could be 110, 80 or 50 if one of them mutates the balance variable
65 at the end depending on which one manages to finish last. It could also
66 be that 2 of them work concurrently and the resultant value is processed
67 by the third transaction.
68
69 |#