(define (enumerate from step)
(cons-stream from (enumerate (+ from step) step)))
(define (accumulate s accumulator init)
;geeft een stream weer te vergelijken met s/(1-x)
(cond ((eq? the-empty-stream (head s))
the-empty-stream)
(else
(let ((el (accumulator (head s) init)))
(cons-stream
el
(accumulate (tail s) accumulator el))))))
(define (map action s)
(if (eq? the-empty-stream s)
the-empty-stream
(cons-stream (action (head s)) (map action (tail s)))))
(define (first n stream)
(if (= n 0)
(begin
(newline)
the-non-printing-object)
(begin
(display (head stream))
(display " ")
(first (-1+ n) (tail stream)))))
(define e-stream
(accumulate
(map
(lambda (x) (/ 1 x))
(accumulate
(enumerate 1 1)
*
1))
+ 1))
;--hierboven waren het zelfgeschreven functies, nu neem ik de functies uit het boek
(define (map proc stream)
(if (empty-stream? stream)
the-empty-stream
(cons-stream (proc (head stream)) (map proc (tail stream)))))
(define (filter pred stream)
(cond ((empty-stream? stream) the-empty-stream)
((pred (head stream))
(cons-stream (head stream) (filter pred (tail stream))))
(else (filter pred (tail stream)))))
(define (accumulate combiner init stream)
(if (empty-stream? stream)
init
(combiner (head stream) (accumulate combiner init (tail stream)))))
(define (enumerate-int low high)
(if (> low high)
the-empty-stream
(cons-stream low (enumerate-int (1+ low) high))))
(define (fac x) (if (= x 0) 1 (* x (fac (-1+ x)))))
(define (calc-sin x n)
(accumulate + 0
(map
(lambda (e) ((if (odd? (quotient e 2)) - +) (/ (expt x e) (fac e))))
(filter
(lambda (n) (odd? n))
(enumerate-int 1 n)))))