]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex3_40.rkt
Solution to 4.33. This had been difficult to get right, though conceptually it was
[sicp.git] / src / sicp / ex3_40.rkt
1 #lang racket
2
3 #|
4
5 (define x 10)
6
7 (parallel-execute (lambda () (set! x (* x x)))
8                   (lambda () (set! x (* x x x))))
9
10 list all possible values of x.
11
12 |#
13
14 #|
15
16 1. 100
17 2. 1000
18 3. (expt 100 3) = 1000000
19 4. (expt (expt 10 3) 2) = 1000000
20 5. (* 10 (* 10 10 10)) = 10000
21 6. (* 10 (* 10 10) (* 10 10)) = 100000
22 7. (* 10 10 (* 10 10)) = 10000
23
24 |#
25
26 #|
27
28 Which of these possibilities remain if we instead use serialized procedures:
29
30 (define x 10)
31
32 (define s (make-serializer))
33
34 (parallel-execute (s (lambda () (set! x (* x x))))
35                   (s (lambda () (set! x (* x x x)))))
36
37 ans:
38
39 => 1000000
40
41 |#