sicp-ex-3.32



<< Previous exercise (3.31) | Index | Next exercise (3.33) >>


  
 ((lambda () (set-signal! output 0)) (lambda () (set-signal! output 1))) 
  
 If the execution order of the above action list changed, the final result of output will be different. 
  

sam

If two or more input-events trigger an output-event simultaneously; we stop the clock.

And do following,

1)change the output-event for input-event1

2)change the output-event for input-event2 (note that this new output-event is calculated with new input-event1).

3)....and so on.

This has to be done in FIFO order. Otherwise, affecting change for input-event2 will not be correct because output-event would then not reflect the changed input-event1.


CrazyAlvaro



 
For and-gate: both a1 a2 have and-action-procedure which contains after-delay

 the point here is that new-value is calculated before delay
 if the segments' list has LIFO, and the first wire a1 change first, then the result will be incorrect
 (a1, a2)
 (0, 1) initial
 (1, 1) a1 0 -> 1, then a1's and-action-procedure called, a1's new-value = 1, lambda procedure inserted into segment
 (1, 0) a2 1 -> 0, then a2's and-action-procedure called, a2's new-value = 0, lambda procedure inserted into segment
 propogate, after-delay
 a2's (lambda() (set-signal! output new-value)) called, set output = 0 
 a1's (lambda() (set-signal! output new-value)) called, set output = 1

 so after this propogation we got output = 1, which is not correct

LinYihai

If someone wants to play with LIFO,alter propagate as follows:

(define (propagate)
(if (empty-agenda? the-agenda)
'done
(let ((first-item (first-agenda-item the-agenda)))
(remove-first-agenda-item! the-agenda)
(propagate)
(first-item))))