mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-29 19:30:36 +02:00
Add record type printer for srfi-41.
* module/srfi/srfi-41.scm: Add record type printer for streams. (stream-promise-visit): New helper for visiting stream promises.
This commit is contained in:
parent
3ed8d953f8
commit
b6e374e535
1 changed files with 23 additions and 0 deletions
|
@ -27,6 +27,7 @@
|
|||
#:use-module (srfi srfi-1)
|
||||
#:use-module (srfi srfi-8)
|
||||
#:use-module (srfi srfi-9)
|
||||
#:use-module (srfi srfi-9 gnu)
|
||||
#:use-module (srfi srfi-26)
|
||||
#:use-module (ice-9 match)
|
||||
#:export (stream-null stream-cons stream? stream-null? stream-pair?
|
||||
|
@ -180,6 +181,28 @@
|
|||
(define-syntax-rule (stream-lambda formals body0 body1 ...)
|
||||
(lambda formals (stream-lazy (begin body0 body1 ...))))
|
||||
|
||||
(define* (stream-promise-visit promise #:key on-eager on-lazy)
|
||||
(define content (stream-promise-val promise))
|
||||
(case (stream-value-tag content)
|
||||
((eager) (on-eager (stream-value-proc content)))
|
||||
((lazy) (on-lazy (stream-value-proc content)))))
|
||||
|
||||
(set-record-type-printer! stream-promise
|
||||
(lambda (strm port)
|
||||
(display "#<stream" port)
|
||||
(let loop ((strm strm))
|
||||
(stream-promise-visit strm
|
||||
#:on-eager (lambda (pare)
|
||||
(cond ((eq? pare %stream-null)
|
||||
(write-char #\> port))
|
||||
(else
|
||||
(write-char #\space port)
|
||||
(stream-promise-visit (stream-kar pare)
|
||||
#:on-eager (cut write <> port)
|
||||
#:on-lazy (lambda (_) (write-char #\? port)))
|
||||
(loop (stream-kdr pare)))))
|
||||
#:on-lazy (lambda (_) (display " ...>" port))))))
|
||||
|
||||
;;; Derived stream functions and macros: (streams derived)
|
||||
|
||||
(define-syntax-rule (define-stream (name . formal) body0 body1 ...)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue