3 (define (inverter input output)
5 (let ((new-value (logical-not (get-signal input))))
6 (after-delay inverter-delay
8 (set-signal! output new-value)))))
10 (add-action! input invert-input)
13 (define (logical-not input)
16 (else (error "LOGICAL-NOT: invalid input value" input))))
18 (define (and-gate a1 a2 output)
19 (define (and-action-procedure)
20 (let ((new-value (logical-and (get-signal a1)
22 (after-delay and-gate-delay
24 (set-signal! output new-value)))))
26 (add-action! a1 and-action-procedure)
27 (add-action! a2 and-action-procedure)
32 (let ((signal-value 0)
33 (action-procedures '()))
34 (define (set-my-signal! new-value)
35 (if (not (= signal-value new-value))
37 (set! signal-value new-value)
38 (call-each action-procedures))
40 (define (accept-action-procedure! proc)
41 (set! action-procedures (cons proc action-procedures))
44 (cond ((eq? m 'set-signal!) set-my-signal!)
45 ((eq? m 'get-signal) signal-value)
46 ((eq? m 'add-action!) accept-action-procedure!)
47 (else (error "Unknown operation -- wire" m))))
50 (define (call-each procedures)
51 (if (null? procedures)
55 (call-each (cdr procedures)))))
57 (define (get-signal wire)
60 (define (set-signal! wire value)
61 ((wire 'set-signal!) value))
63 (define (add-action! wire proc)
64 ((wire 'add-action!) proc))