diff options
author | Mark H Weaver <mhw@netris.org> | 2013-03-20 20:29:04 -0400 |
---|---|---|
committer | Mark H Weaver <mhw@netris.org> | 2013-03-20 20:29:04 -0400 |
commit | 821becfc39399d35d92643ed77171374aa781318 (patch) | |
tree | 436bc462bfca6fcbee85420c4202736b93fea29d | |
parent | a540215119c43f3ad5c3491f249fc6dc1869a921 (diff) | |
download | guile-821becfc39399d35d92643ed77171374aa781318.tar.gz |
Make 'stream-fold-aux' an inlined procedure.
Suggested by Ian Price <ianprice90@googlemail.com>.
* module/srfi/srfi-41.scm (stream-fold-aux): Use 'define-inlinable'
and change the optional 'limit' argument into a required argument.
Move it above all uses.
(stream-fold): Pass required 'limit' argument to 'stream-fold-aux'.
-rw-r--r-- | module/srfi/srfi-41.scm | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/module/srfi/srfi-41.scm b/module/srfi/srfi-41.scm index 09e454740..16596cef4 100644 --- a/module/srfi/srfi-41.scm +++ b/module/srfi/srfi-41.scm @@ -208,6 +208,15 @@ ((_) stream-null) ((_ x y ...) (stream-cons x (stream y ...))))) +;; Common helper for the various eager-folding functions, such as +;; stream-fold, stream-drop, stream->list, stream-length, etc. +(define-inlinable (stream-fold-aux proc base strm limit) + (do ((val base (and proc (proc val (stream-car strm)))) + (strm strm (stream-cdr strm)) + (limit limit (and limit (1- limit)))) + ((or (and limit (zero? limit)) (stream-null? strm)) + (values val strm limit)))) + (define stream->list (case-lambda ((strm) (stream->list #f strm)) @@ -291,16 +300,7 @@ (define (stream-fold proc base strm) (must procedure? proc 'stream-fold "non-procedural argument") (must stream? strm 'stream-fold "non-stream argument") - (first-value (stream-fold-aux proc base strm))) - -;; Common helper for the various eager-folding functions, such as -;; stream-fold, stream-drop, stream->list, stream-length, etc. -(define* (stream-fold-aux proc base strm #:optional limit) - (do ((val base (and proc (proc val (stream-car strm)))) - (strm strm (stream-cdr strm)) - (limit limit (and limit (1- limit)))) - ((or (and limit (zero? limit)) (stream-null? strm)) - (values val strm limit)))) + (first-value (stream-fold-aux proc base strm #f))) (define stream-for-each (case-lambda |