Answer 3.31
This commit is contained in:
@@ -19,8 +19,8 @@
|
|||||||
(call-each action-procedures))
|
(call-each action-procedures))
|
||||||
'done))
|
'done))
|
||||||
(define (accept-action-procedure! proc)
|
(define (accept-action-procedure! proc)
|
||||||
(set! action-procedures (cons proc action-procedures))
|
(set! action-procedures (cons proc action-procedures)))
|
||||||
(proc))
|
; (proc))
|
||||||
(define (dispatch m)
|
(define (dispatch m)
|
||||||
(cond ((eq? m 'get-signal) signal-value)
|
(cond ((eq? m 'get-signal) signal-value)
|
||||||
((eq? m 'set-signal!) set-my-signal!)
|
((eq? m 'set-signal!) set-my-signal!)
|
||||||
@@ -200,6 +200,9 @@
|
|||||||
(assert (get-signal s3) 0)
|
(assert (get-signal s3) 0)
|
||||||
(assert (get-signal co) 1))
|
(assert (get-signal co) 1))
|
||||||
|
|
||||||
|
|
||||||
|
(display "\nex-3.31 - accept-action-procedure!\n")
|
||||||
|
|
||||||
(define input-1 (make-wire))
|
(define input-1 (make-wire))
|
||||||
(define input-2 (make-wire))
|
(define input-2 (make-wire))
|
||||||
(define sum (make-wire))
|
(define sum (make-wire))
|
||||||
@@ -207,14 +210,21 @@
|
|||||||
; (probe 'sum sum)
|
; (probe 'sum sum)
|
||||||
; (probe 'carry carry)
|
; (probe 'carry carry)
|
||||||
|
|
||||||
(half-adder input-1 input-2 sum carry)
|
|
||||||
(set-signal! input-1 1)
|
(set-signal! input-1 1)
|
||||||
(set-signal! input-2 1)
|
(set-signal! input-2 1)
|
||||||
|
(half-adder input-1 input-2 sum carry)
|
||||||
(propagate)
|
(propagate)
|
||||||
|
|
||||||
(assert (get-signal sum) 0)
|
(assert (get-signal sum) 0)
|
||||||
(assert (get-signal carry) 1)
|
(assert (get-signal carry) 1)
|
||||||
|
|
||||||
(display "\nex-3.31\n")
|
; It is necessary to call the action procedure upon the initialization of the
|
||||||
|
; gate to make sure that all wires are set to their correct value initially.
|
||||||
|
|
||||||
|
; For the example with the half-adder the carry-bit stays at zero because the
|
||||||
|
; AND-gate is not initialized to the correct value for two 1s as input. To
|
||||||
|
; avoid the issue we would have to make sure that each signal changes at least
|
||||||
|
; one.
|
||||||
|
|
||||||
|
(display "\nex-3.32\n")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user