遅延ストリーム

おつかれ気味なので、SICP勉強会用につくってる遅延ストリームをはってごまかす。10分程度でつくった代物。

(define-syntax cons-stream
  (syntax-rules()
    ((_ x y) (cons x (delay y)))))
(define (stream-car stream) (car stream))
(define (stream-cdr stream) (force (cdr stream)))

(define (stream-enumarate-interval low high)
  (cons-stream low
	       (stream-enumarate-interval (+ low 1) high)))

(define (stream-ref s n)
  (if (= n 0) 
      (stream-car s)
      (stream-ref (stream-cdr s) (- n 1))))

(define (stream-map proc s)
  (cons-stream (proc (stream-car s))
	       (stream-map proc (stream-cdr s))))