guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stream-for-each 2 or more bug


From: Kevin Ryde
Subject: Re: stream-for-each 2 or more bug
Date: Sat, 11 Sep 2004 07:49:11 +1000
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (gnu/linux)

Andy Wingo <address@hidden> writes:
>
> it's too bad users have to wait until 1.8 to see them!

The bug fixes (outright bugs) are in the 1.6 branch too, 1.6.5 is
supposed to be out soon. :)

> (define (stream-filter pass? stream)
>   "Selects from @var{stream} only those elements that satisfy the
> predicate @var{pass?}."
>   (cond
>    ((stream-null? stream) stream)
>    ((pass? (stream-car stream))

I was thinking of something with make-stream, like (untested)

    (define (stream-filter pred stream)
      (define (gen stream)
        (let ((pair (force stream)))
          (and (pair? pair)
               (if (pred (car pair))
                   pair
                   (gen (cdr pair))))))
      (make-stream gen stream))

Or maybe explicitly fiddling with delay/force to save some function
calls.

>     (stream-cons (stream-car stream)
>                  (stream-filter pass? (stream-cdr stream))))

I don't think stream-cons exists actually.  What sicp shows is a
macro, I guess that's necessary for recursive definitions.  Not sure
if a macro is good thing or not though, overall.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]