[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
stream-partition is not incremental
I hope this comment is still relevant, as I joined the
discussion rather late. It intersects somewhat with
the discussions on space retention and stream-unfoldn.
The reference implementation of stream-partition
appears to evaluate the entire stream before returning
any results. As such, it has no advantages over a
function that operates on lists.
;; Obvious quick fix: This tests each element twice,
;; and it may have problems with space retention.
(define (stream-partition pred? strm)
(stream-filter pred? strm)
(stream-filter (lambda (x) (not (pred? x)))
It might be possible to write a stream-partition that
was incremental but still tested each element only
once. However, I think it would require explicit
shared state between the two result streams.
Do you Yahoo!?
Yahoo! Web Hosting - establish your business online