首页 > 其他 > 详细

【SICP练习】112 练习3.28

时间:2015-03-26 15:00:10      阅读:220      评论:0      收藏:0      [点我收藏+]

练习3-28

原文

Exercise 3.28. Define an or-gate as a primitive function box. Your or-gate constructor should be similar to and-gate.

代码

(define (or-gate input-1 input-2 output)
    (define (or-action-procedure)
        (let ((new-value
                (logical-or (get-signal input-1) (get-signal input-2))))
            (after-delay or-gate-delay
                         (lambda ()
                            (set-signal! output new-value)))))
    (add-action! input-1 or-action-procedure)
    (add-action! input-2 or-action-procedure)
    ‘ok)

(define (logical-or x y)
    (if (or (= x 1) (= y 1))
        1
        0))

【SICP练习】112 练习3.28

原文:http://blog.csdn.net/nomasp/article/details/44648311

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!