Sunday, 2 June 2013

+: expects type as 2nd argument, given: #;

+: expects type <number> as 2nd argument, given: #<void>;

I'm currently working on exercise 1.29 of SICP, and my program keeps giving me the following error:
+: expects type <number> as 2nd argument, given: #<void>; other arguments were: 970299/500000
Here's the code I'm running using racket:
(define (integral2 f a b n)
    (define (get-mult k)
      (cond ((= k 0) 1)
            ((even? k) 4)
            (else 2)))
    (define (h b a n)
      (/ (- b a) n))
    (define (y f a b h k)
      (f (+ a (* k (h b a n)))))
    (define (iter f a b n k)
      (cond ((> n k)
             (+ (* (get-mult k)
                   (y f a b h k))
                (iter f a b n (+ k 1))))))
    (iter f a b n 0))

(integral2 cube 0 1 100)
I'm guessing the "2nd argument" is referring to the place where I add the current iteration and future iterations. However, I don't understand why that second argument isn't returning a number. Does anyone know how to remedy this error?

No comments:

Post a Comment