読者です 読者をやめる 読者になる 読者になる

(wat-aro)

無職から有職者にランクアップしました

SICP 問題 3.60

scheme SICP
(define (stream-head s n)
  (let iter ((s s)
             (n n))
    (if (zero? n)
        'done
        (begin
          (display (stream-car s))
          (display " ")
          (iter (stream-cdr s) (- n 1))))))


(define (mul-series s1 s2)
  (cons-stream (* (stream-car s1)
                  (stream-car s2))
               (add-streams
                (scale-stream (stream-cdr s2) (stream-car s1))
                (mul-series (stream-cdr s1) s2))))

(define circles (add-streams (mul-series sine-series sine-series)
                             (mul-series cosine-series cosine-series)))
gosh> (stream-head circles 10)
1 0 0 0 0 0 0 0 0 0 done