- stream-unfoldn generator seed nprocedure
stream-unfoldn returns n streams whose contents are produced by successive calls to generator, which takes the current seed as an arguments and returns n + 1 values:
(proc seed) -> seed result0 ... resultN
where resultI indicates how to produce the next element of the Ith result stream:
- (value)
- value is the next car of this result stream
- #f
- no new information for this result stream
- ()
- the end of this result stream has been reached
Note that getting the next element in any particular result stream may require multiple calls to generator.
(define (take5 s) (stream-unfoldn (lambda (x) (let ((n (car x)) (s (cdr x))) (if (zero? n) (values 'dummy '()) (values (cons (- n 1) (stream-cdr s)) (list (stream-car s)))))) (cons 5 s) 1)) (take5 from0) => (stream 0 1 2 3 4)