Why isn't '(sum-milt-iter three five a b sum1 sum2)' evaluating to 23 given
that '(mult-sum 5)' and '(mult-sum 3)' return the right answer, namely 5 and
; linear iterative process for computing the sum of the multiples of 3 and 5 <
(define (sum-mult three five)
(sum-mult-iter three five 1 1 0 0))
(define (sum-mult-iter three five a b sum1 sum2)
[(and (>= (* five b) 10)
(> (* three a) 10)
(+ sum1 sum2))]
(sum-mult-iter three five (+ a 1) (+ b 1) (+ sum1 (* three a)) (+
sum2 (* five b)))]))
; Ive spent some time trying to understand why '(+ sum1 sum2)' does not
evaluate to 23, but I cannot see why.
(define (mult-sum five)
(mult-sum-iterator five 1 0) )
(define (mult-sum-iterator five b sum2)
(if (>= (* five b) 10)
(mult-sum-iterator five (+ b 1) (+ sum2 (* five b))))
> (milt-sum 5) ; 5
and likewise '(milt-sum three)' evaluates to 18.
(define (mult-sum three)
(mult-sum-iterator three 1 0) )
(define (mult-sum-iterator three a sum2)
(if (>= (* five a) 10)
(mult-sum-iterator five (+ a 1) (+ sum2 (* five a))))
> (mult-sum 3) ; 18
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
For more options, visit https://groups.google.com/d/optout.