[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] GNU Guile branch, srfi-41, updated. v2.0.7-211-g22ee2f7
From: |
Chris K. Jester-Young |
Subject: |
[Guile-commits] GNU Guile branch, srfi-41, updated. v2.0.7-211-g22ee2f7 |
Date: |
Tue, 19 Mar 2013 21:52:59 +0000 |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Guile".
http://git.savannah.gnu.org/cgit/guile.git/commit/?id=22ee2f7dc985ffadaf5603256eab94a8c650759c
The branch, srfi-41 has been updated
via 22ee2f7dc985ffadaf5603256eab94a8c650759c (commit)
via 9069f1c18eedfe46e2a3d1d2bc5ff9ba14a9a02a (commit)
from a19b88beb016cb3dacdb8962165b599c5743c167 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 22ee2f7dc985ffadaf5603256eab94a8c650759c
Author: Chris K. Jester-Young <address@hidden>
Date: Tue Mar 19 17:46:51 2013 -0400
Simplify stream? so that the promise doesn't need forcing.
* module/srfi/srfi-41.scm: The major change here is that instead of
using (srfi srfi-45) directly, we use an independent promise type,
so that anything that's that promise type are going to be streams.
Currently, we use copy-and-paste to create this independent type,
just as in the reference implementation; it's unpleasant, but we
hope to find a better way soon.
(stream?): Define as stream-promise?.
(stream-null): Use stream-eager rather than stream-delay. I don't
see why the reference implementation chose to use delay there.
(stream-unfolds): Now that stream? doesn't prematurely force the
stream, it's possible to use stream-append to join up the streams.
commit 9069f1c18eedfe46e2a3d1d2bc5ff9ba14a9a02a
Author: Chris K. Jester-Young <address@hidden>
Date: Tue Mar 19 17:11:15 2013 -0400
Fix typo. Thanks to Mark H. Weaver for the catch.
* module/srfi/srfi-41.scm (stream-append): Fix typo.
-----------------------------------------------------------------------
Summary of changes:
module/srfi/srfi-41.scm | 49 ++++++++++++++++++++++++++++++++++++++--------
1 files changed, 40 insertions(+), 9 deletions(-)
diff --git a/module/srfi/srfi-41.scm b/module/srfi/srfi-41.scm
index 91d2c67..9e82c99 100644
--- a/module/srfi/srfi-41.scm
+++ b/module/srfi/srfi-41.scm
@@ -28,9 +28,6 @@
#:use-module (srfi srfi-8)
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-26)
- #:use-module ((srfi srfi-45)
- #:select (lazy eager delay force promise?)
- #:renamer (symbol-prefix-proc 'stream-))
#:use-module (ice-9 match)
#:export (stream-null stream-cons stream? stream-null? stream-pair?
stream-car stream-cdr stream-lambda define-stream
@@ -84,12 +81,47 @@
((_ name syntax)
(define-syntax name syntax))))
+;;; Copy-and-paste of Mark H. Weaver's version of SRFI 45. Once we have
+;;; better support for creating an independent promise type, we'll use
+;;; that instead.
+
+(define-record-type stream-promise (make-stream-promise val) stream-promise?
+ (val stream-promise-val stream-promise-val-set!))
+
+(define-record-type stream-value (make-stream-value tag proc) stream-value?
+ (tag stream-value-tag stream-value-tag-set!)
+ (proc stream-value-proc stream-value-proc-set!))
+
+(define-syntax-rule (stream-lazy exp)
+ (make-stream-promise (make-stream-value 'lazy (lambda () exp))))
+
+(define (stream-eager . xs)
+ (make-stream-promise (make-stream-value 'eager xs)))
+
+(define-syntax-rule (stream-delay exp)
+ (stream-lazy (call-with-values
+ (lambda () exp)
+ stream-eager)))
+
+(define (stream-force promise)
+ (let ((content (stream-promise-val promise)))
+ (case (stream-value-tag content)
+ ((eager) (apply values (stream-value-proc content)))
+ ((lazy) (let* ((promise* ((stream-value-proc content)))
+ (content (stream-promise-val promise)))
+ (if (not (eqv? (stream-value-tag content) 'eager))
+ (begin (stream-value-tag-set! content
+ (stream-value-tag
(stream-promise-val promise*)))
+ (stream-value-proc-set! content
+ (stream-value-proc
(stream-promise-val promise*)))
+ (stream-promise-val-set! promise* content)))
+ (stream-force promise))))))
+
;;; Primitive stream functions and macros: (streams primitive)
-(define (stream? obj)
- (or (stream-pair? obj) (stream-null? obj)))
+(define stream? stream-promise?)
-(define stream-null (stream-delay '(stream . null)))
+(define stream-null (stream-eager '(stream . null)))
(define (stream-null? obj)
(and (stream-promise? obj)
@@ -159,7 +191,7 @@
(reverse! (first-value (stream-fold-aux xcons '() strm n))))))
(define (stream-append . strms)
- (must-every stream? strms 'stread-append "non-stream argument")
+ (must-every stream? strms 'stream-append "non-stream argument")
(stream-let recur ((strms strms))
(if (null? strms) stream-null
(let ((strm (car strms)))
@@ -403,8 +435,7 @@
(() stream-null)
(#f (tail))
((item) (stream-cons item (tail)))
- ;; Can't use stream-append, since the call to tail must be delayed.
- ((? list? items) (stream-concat (stream (list->stream items) (tail))))))
+ ((? list? items) (stream-append (list->stream items) (tail)))))
(must procedure? gen 'stream-unfolds "non-procedural argument")
(let ((genstrm (generator-stream seed)))
hooks/post-receive
--
GNU Guile
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Guile-commits] GNU Guile branch, srfi-41, updated. v2.0.7-211-g22ee2f7,
Chris K. Jester-Young <=