SICP Exercise 3.30
Question
Figure 3.27 shows a ripple-carry adder formed by stringing together
Write a procedure ripple-carry-adder
that generates this circuit. The
procedure should take as arguments three lists of
Answer
I have to use mcar
and mcdr
here because of some workarounds that were
needed to get the circuit simulator to work. They basically do the same thing as
car
and cdr
.
(define (ripple-carry-adder a b s c)
(if (null? a)
(begin (set-signal! c 0) c)
(begin
(full-adder
(mcar a)
(mcar b)
(ripple-carry-adder
(mcdr a)
(mcdr b)
(mcdr s)
(make-wire))
(mcar s)
c)
c)))