]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex3_31.rkt
Solution to 4.33. This had been difficult to get right, though conceptually it was
[sicp.git] / src / sicp / ex3_31.rkt
1 #lang racket
2
3 #|
4
5 If we don't call the proc in the add-action! procedure then the outputs for the 
6 given inputs will be in some undefined default states. They won't reflect the 
7 logic that the function blocks are representing.
8
9 Let us take half adder example:
10
11 (define (half-adder a b s c)
12   (let ((d (make-wire)) (e (make-wire)))
13     (or-gate a b d)
14     (and-gate a b c)
15     (inverter c e)
16     (and-gate d e s)
17     'ok))
18
19 The gate procedures like inverter and or-gate calls add-action! which
20 is the procedure which adds the gate operation to the agenda. If it
21 is not called once, then the operation is not added into the agenda.
22
23 If accept-action-proc! is defined without the call to proc, i.e.
24
25 (define (accept-action-proc! proc)
26   (set! action-procedures (cons proc action-procedures))
27
28 then, let us see what happens.
29
30 The or-gate definition will call add-action on both its inputs a and b. make-wire 
31 by default sets the wire value as 0. So, for the default case, the inputs to the
32 half-adder will be 0 and 0 and the output of the or-gate and and-gate will be 0.
33 i.e. D = 0, C = 0.
34 E will also be 0. So, S = 0 C = 0, irrespective of the initial values of a and b.
35
36 |#