3 (define (stream-car s) (car s))
4 (define (stream-cdr s) (force (cdr s)))
6 (define (stream-ref s n)
9 (stream-ref (stream-cdr s)
12 (define (stream-map proc s)
15 (cons-stream (proc (stream-car s))
16 (stream-map proc (stream-cdr s)))))
18 (define (stream-filter pred? s)
19 (cond [(stream-null? s) the-empty-stream]
20 [(pred? (stream-car s))
21 (cons-stream (stream-car s)
22 (stream-filter pred? (stream-cdr s)))]
23 [else (stream-filter pred? (stream-cdr s))]))
25 (define (stream-for-each proc s)
30 (stream-for-each proc (stream-cdr s)))))
32 (define (display-stream s)
33 (stream-for-each display-line s))
35 (define (display-line x)
39 ;; stream-enumerate-interval
40 (define (stream-enumerate-interval low high)
44 (stream-enumerate-interval (+ low 1)
49 (define (square x) (* x x))
50 (define (smallest-divisor n)
52 (define (find-divisor n test-divisor)
53 (cond ((> (square test-divisor) n) n)
54 ((divides? test-divisor n) test-divisor)
55 (else (find-divisor n (+ test-divisor 1)))))
56 (define (divides? a b)
57 (= (remainder b a) 0))
60 (= (smallest-divisor n) n))