mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-22 03:30:22 +02:00
* streams.scm (stream-fold, stream-for-each): don't use named let,
because it prevents the gc from junking the stream argument.
This commit is contained in:
parent
50fecba92d
commit
b87e3d4d19
2 changed files with 39 additions and 17 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2000-04-03 Michael Livshin <mlivshin@bigfoot.com>
|
||||||
|
|
||||||
|
* streams.scm (stream-fold, stream-for-each): don't use named let,
|
||||||
|
because it prevents the gc from junking the stream argument.
|
||||||
|
|
||||||
Thu Mar 9 08:05:08 2000 Greg J. Badros <gjb@cs.washington.edu>
|
Thu Mar 9 08:05:08 2000 Greg J. Badros <gjb@cs.washington.edu>
|
||||||
|
|
||||||
* slib.scm: Back-out change to software-type -- renamed
|
* slib.scm: Back-out change to software-type -- renamed
|
||||||
|
|
|
@ -157,25 +157,42 @@ If STREAM has infinite length this procedure will not terminate."
|
||||||
|
|
||||||
(define (stream-fold f init stream . rest)
|
(define (stream-fold f init stream . rest)
|
||||||
(if (null? rest) ;fast path
|
(if (null? rest) ;fast path
|
||||||
(let loop ((stream stream) (r init))
|
(stream-fold-one f init stream)
|
||||||
(if (stream-null? stream)
|
(stream-fold-many f init (cons stream rest))))
|
||||||
r
|
|
||||||
(loop (stream-cdr stream) (f (stream-car stream) r))))
|
(define (stream-fold-one f r stream)
|
||||||
(let loop ((streams (cons stream rest)) (r init))
|
(if (stream-null? stream)
|
||||||
(if (or-map stream-null? streams)
|
r
|
||||||
r
|
(stream-fold-one f (f (stream-car stream) r) (stream-cdr stream))))
|
||||||
(loop (map stream-cdr streams)
|
|
||||||
(apply f (let recur ((cars (map stream-car streams)))
|
(define (stream-fold-many f r streams)
|
||||||
(if (null? cars)
|
(if (or-map stream-null? streams)
|
||||||
(list r)
|
r
|
||||||
(cons (car cars)
|
(stream-fold-many f
|
||||||
(recur (cdr cars)))))))))))
|
(apply f (let recur ((cars
|
||||||
|
(map stream-car streams)))
|
||||||
|
(if (null? cars)
|
||||||
|
(list r)
|
||||||
|
(cons (car cars)
|
||||||
|
(recur (cdr cars))))))
|
||||||
|
(map stream-cdr streams))))
|
||||||
|
|
||||||
(define (stream-for-each f stream . rest)
|
(define (stream-for-each f stream . rest)
|
||||||
(apply stream-fold
|
(if (null? rest) ;fast path
|
||||||
(lambda (elt _) (f elt))
|
(stream-for-each-one f stream)
|
||||||
#f
|
(stream-for-each-many f (cons stream rest))))
|
||||||
stream rest))
|
|
||||||
|
(define (stream-for-each-one f stream)
|
||||||
|
(if (not (stream-null? stream))
|
||||||
|
(begin
|
||||||
|
(f (stream-car stream))
|
||||||
|
(stream-for-each-one f (stream-cdr stream)))))
|
||||||
|
|
||||||
|
(define (stream-for-each-may f streams)
|
||||||
|
(if (not (or-map stream-null? streams))
|
||||||
|
(begin
|
||||||
|
(apply f (map stream-car streams))
|
||||||
|
(stream-for-each-one f (map stream-cdr streams)))))
|
||||||
|
|
||||||
(define (stream-map f stream . rest)
|
(define (stream-map f stream . rest)
|
||||||
"Returns a newly allocated stream, each element being the result of
|
"Returns a newly allocated stream, each element being the result of
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue