SICP 3.28 3.29 3.30

原创
2017/10/03 17:01
阅读数 71

3.28

(define (or-gate a b output)
  (define (or-action)
    (let ((new-value (logic-or (get-signal a) (get-signal b))))
      (after-delay or-gate-delay (lambda () (set-signal! output new-value)))))
  (add-action! a or-action)
  (add-action! b or-action)
  'ok)

3.29

a ∨ b == ~~(a ∨ b) == ~(~a ∧ ~b)

(define (or-gate a b output)
  (let ((a-out (make-wire))
        (b-out (make-wire))
        (and-out (make-wire)))
    (inverter a a-out)
    (inverter b b-out)
    (and-gate a-out b-out and-out)
    (inverter and-out output)))

3.30

(define (ripple-carry-adder a b s c)
  (if (null? (cdr a))
      (let ((cn (make-wire)))
        (full-adder (car a) (car b) cn (car s) c))
      (let ((ck (make-wire)))
        (ripple-carry-adder (cdr a) (cdr b) (cdr s) ck)
        (full-adder (car a) (car b) ck (car s) c))))

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部