Chapter 3, Modularity, Objects, and State

Exercise 3.34


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
1 ]=> (define (squarer a b) (multiplier a a b))

;Value: squarer

1 ]=> (define x1 (make-connector))

;Value: x1

1 ]=> (define sqr (make-connector))

;Value: sqr

1 ]=> (squarer x1 sqr)

;Value 33: #[compound-procedure 33 me]

1 ]=> (probe "x1" x1)

;Value 34: #[compound-procedure 34 me]

1 ]=> (probe "square" sqr)

;Value 35: #[compound-procedure 35 me]

1 ]=> (set-value! x1 10 'ovais)

Probe: x1 = 10
Probe: square = 100
;Value: done

1 ]=> (forget-value! x1 'ovais)

Probe: x1 = ?
Probe: square = ?
;Value: done

1 ]=> (set-value! sqr 125 'ovais)

Probe: square = 125
;Value: done

1 ]=> (has-value? x1)

;Value: #f

1 ]=> 

The problem is when we set the square, it does not automatically set a - because of this line in multiplier:

1
((and (has-value? product) (has-value? m1))

For a multiplier, this is indeed the correct behavior for the multiplier. The problem lies in our squarer because multiplier is not aware/can not be aware of the inputs a and b are same.