Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
53 lines (45 sloc) 1.43 KB
(define (logical-not s)
(cond ((= s 0) 1)
((= s 1) 0)
(else (error "Invalid signal" s))))
(define (logical-and s1 s2)
(cond ((and (= s1 1) (= s2 1)) 1)
((not (or (= s1 0) (= s1 1)))
(error "Invalid signal" s1))
((not (or (= s2 0) (= s2 1)))
(error "Invalid signal" s2))
(else 0)))
(define (logical-or s1 s2)
(cond ((and (= s1 0) (= s2 0)) 0)
((not (or (= s1 0) (= s1 1)))
(error "Invalid signal" s1))
((not (or (= s2 0) (= s2 1)))
(error "Invalid signal" s2))
(else 1)))
(define (inverter input output)
(define (invert-input)
(let ((new-value (logical-not (get-signal input))))
(after-delay inverter-delay
(lambda ()
(set-signal! output new-value)))))
(add-action! input invert-input)
'ok)
(define (and-gate a1 a2 output)
(define (and-action-procedure)
(let ((new-value
(logical-and (get-signal a1) (get-signal a2))))
(after-delay and-gate-delay
(lambda ()
(set-signal! output new-value)))))
(add-action! a1 and-action-procedure)
(add-action! a2 and-action-procedure)
'ok)
(define (or-gate a b output)
(let ((c (make-wire))
(d (make-wire))
(e (make-wire)))
(inverter a c)
(inverter b d)
(and-gate c d e)
(inverter e output)))
;;delay will be 3 * inverter-delay + and-gate-delay
Jump to Line
Something went wrong with that request. Please try again.