【SICP习题】113 练习3.33

【SICP练习】113 练习3.33

练习3-33

原文

Exercise 3.33. Using primitive multiplier, adder, and constant constraints, define a procedure averager that takes three connectors a, b, and c as inputs and establishes the constraint that the value of c is the average of the values of a and b.

代码

(define (averager a b c)
    (let ((sum (make-connector))
          (d (make-connector)))
        (adder a b sum)
        (multiplier sum d c)
        (constant (/ 1 2) d)
        'ok))