1

"Use your partial sum function and the sequence in 3a to produce a stream containing successive approximations to sin(x)"

I'm assuming the question is for me to have the value return, however, the output is "#< stream >" instead. What is wrong with my code or what am I missing?

my code for the said 3a is:

(define (sin-stream x)
  (define(fact n)
    (if (= n 1)
        1
        (* n (fact (- n 1)))))
  (define (sign k)
    (if (even? k)
        1 -1))
  (define (sin-str-term x k)
    (/ (* (sign k)
          (expt x (+ (* 2 k) 1)))
       (fact (+ (* 2 k) 1))))
  (define (sin-helper x k)
    (stream-cons (sin-str-term x k)
                 (sin-helper x (+ k 1))))
  (sin-helper x 0))

and the code I used for the partial sum function is:

(define (partial-sums s)
  (stream-cons (stream-car s)
           (add-streams (stream-cdr s) (partial-sums s))))

and the code I use to call the sin approximation is:

(define (sin-approx x)
  (partial-sums (sin-stream x)))
seaweed
  • 21
  • 2
  • 1
    The value is supposed to be a stream, and it seems to be a stream. Perhaps you need to review what a stream is and how it works. – molbdnilo May 03 '19 at 05:19

1 Answers1

0

The stream can't be displayed directly because it's an infinite object.

What you might want to do is implement a function stream->list or stream-take that takes a stream and a number and returns that many elements from the stream.

river
  • 1,028
  • 6
  • 16