Answer 3.31

main
Felix Martin 2020-12-25 15:33:26 -05:00
parent 51f723f386
commit 861b8fe73e
1 changed files with 14 additions and 4 deletions

View File

@ -19,8 +19,8 @@
(call-each action-procedures))
'done))
(define (accept-action-procedure! proc)
(set! action-procedures (cons proc action-procedures))
(proc))
(set! action-procedures (cons proc action-procedures)))
; (proc))
(define (dispatch m)
(cond ((eq? m 'get-signal) signal-value)
((eq? m 'set-signal!) set-my-signal!)
@ -200,6 +200,9 @@
(assert (get-signal s3) 0)
(assert (get-signal co) 1))
(display "\nex-3.31 - accept-action-procedure!\n")
(define input-1 (make-wire))
(define input-2 (make-wire))
(define sum (make-wire))
@ -207,14 +210,21 @@
; (probe 'sum sum)
; (probe 'carry carry)
(half-adder input-1 input-2 sum carry)
(set-signal! input-1 1)
(set-signal! input-2 1)
(half-adder input-1 input-2 sum carry)
(propagate)
(assert (get-signal sum) 0)
(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")