[plt-scheme] The place of streams?

From: Eli Barzilay (eli at barzilay.org)
Date: Fri Jun 22 00:25:36 EDT 2007

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!


Posted on the users mailing list.