]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex3_31.rkt
4b78357d62230364de4f85ee62b7890effffd5f3
[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 If accept-action-proc! is defined without the call to proc, i.e.
20
21 (define (accept-action-proc! proc)
22   (set! action-procedures (cons proc action-procedures))
23
24 then, let us see what happens.
25
26 The or-gate definition will call add-action on both its inputs a and b. make-wire 
27 by default sets the wire value as 0. So, for the default case, the inputs to the
28 half-adder will be 0 and 0 and the output of the or-gate and and-gate will be 0.
29 i.e. D = 0, C = 0.
30 E will also be 0. So, S = 0 C = 0, irrespective of the initial values of a and b.
31
32 |#