* [PATCH] SRFI 41: Improve stream-constant and list->stream implementations
@ 2015-11-03 1:27 Chris Jester-Young
2015-11-03 19:56 ` Chris Jester-Young
0 siblings, 1 reply; 2+ messages in thread
From: Chris Jester-Young @ 2015-11-03 1:27 UTC (permalink / raw)
To: guile-devel
[-- Attachment #1: Type: text/plain, Size: 691 bytes --]
Attached is a patch to implement the changes detailed in
http://srfi-email.schemers.org/srfi-41/msg/3066997, which improves
the performance of `stream-constant` compared to the reference
implementation.
It probably doesn't improve performance against the Guile version
(which is already O(1) per element), but it's a cleaner implementation
that removes the need for the `list?` shadowing hack in `list->stream`.
This also removes support for circular lists for `list->stream` (which
was never supported in the reference implementation, and was added as
an implementation detail of `stream-constant` (which I originally
implemented using circular lists).
Comments welcome.
Cheers,
Chris.
[-- Attachment #2: Type: message/rfc822, Size: 1154 bytes --]
From: Chris Jester-Young <cky@cky.nz>
Subject: [PATCH] SRFI 41: Improve stream-constant performance.
Date: Tue, 3 Nov 2015 14:10:36 +1300
See http://srfi-email.schemers.org/srfi-41/msg/3066997 for more details.
---
module/srfi/srfi-41.scm | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/module/srfi/srfi-41.scm b/module/srfi/srfi-41.scm
index 3589b35..59c3b50 100644
--- a/module/srfi/srfi-41.scm
+++ b/module/srfi/srfi-41.scm
@@ -212,8 +212,6 @@
((letrec ((tag (stream-lambda (name ...) body1 body2 ...))) tag) val ...))
(define (list->stream objs)
- (define (list? x)
- (or (proper-list? x) (circular-list? x)))
(must list? objs 'list->stream "non-list argument")
(stream-let recur ((objs objs))
(if (null? objs) stream-null
@@ -274,7 +272,9 @@
(define stream-constant
(case-lambda
(() stream-null)
- (objs (list->stream (apply circular-list objs)))))
+ ((obj) (stream-let loop () (stream-cons obj (loop))))
+ (objs (define strm (list->stream objs))
+ (stream-let loop () (stream-append strm (loop))))))
(define-syntax* (stream-do x)
(define (end x)
--
2.3.8 (Apple Git-58)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] SRFI 41: Improve stream-constant and list->stream implementations
2015-11-03 1:27 [PATCH] SRFI 41: Improve stream-constant and list->stream implementations Chris Jester-Young
@ 2015-11-03 19:56 ` Chris Jester-Young
0 siblings, 0 replies; 2+ messages in thread
From: Chris Jester-Young @ 2015-11-03 19:56 UTC (permalink / raw)
To: guile-devel
On Tue, Nov 03, 2015 at 02:27:20PM +1300, Chris Jester-Young wrote:
> Date: Tue, 3 Nov 2015 14:10:36 +1300
> From: Chris Jester-Young <cky@cky.nz>
> Subject: [PATCH] SRFI 41: Improve stream-constant performance.
>
> See http://srfi-email.schemers.org/srfi-41/msg/3066997 for more details.
> ---
Please disregard this patch; it's missing the required ChangeLog. My
other thread on the list, that does include the ChangeLog in the commit
message, is good to go.
Many thanks,
Chris.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-11-03 19:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-03 1:27 [PATCH] SRFI 41: Improve stream-constant and list->stream implementations Chris Jester-Young
2015-11-03 19:56 ` Chris Jester-Young
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).