[plt-scheme] The place of streams?
On Jun 21, Danny Yoo wrote:
>
> > It sounds like a stream could be used here, and I wouldn't need to
> > rewrite my function.
>
> I think the only thing that might need a change is the use of
> FIRST/REST with the equivalent operations for streams.
An alternative that I have to mention here is Lazy Scheme, where you
can write simpler code (and it is fully lazy, unlike streams that are
only lazy in the tail position):
(define nats (cons 1 (map add1 nats)))
(define (divides? n m)
(zero? (modulo m n)))
(define (sift n l)
(filter (lambda (x) (not (divides? n x))) l))
(define (sieve l)
(cons (car l) (sieve (sift (car l) (cdr l)))))
(define primes (sieve (cdr nats)))
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!