mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
Add record type printer for srfi-45.
* module/srfi/srfi-45.scm: Add record type printer for promises. (promise-visit): New helper for visiting lazy promises.
This commit is contained in:
parent
7f6c3f8f00
commit
3ed8d953f8
1 changed files with 16 additions and 1 deletions
|
@ -39,7 +39,8 @@
|
||||||
eager
|
eager
|
||||||
promise?)
|
promise?)
|
||||||
#:replace (delay force promise?)
|
#:replace (delay force promise?)
|
||||||
#:use-module (srfi srfi-9))
|
#:use-module (srfi srfi-9)
|
||||||
|
#:use-module (srfi srfi-9 gnu))
|
||||||
|
|
||||||
(cond-expand-provide (current-module) '(srfi-45))
|
(cond-expand-provide (current-module) '(srfi-45))
|
||||||
|
|
||||||
|
@ -76,3 +77,17 @@
|
||||||
;; (*) These two lines re-fetch and check the original promise in case
|
;; (*) These two lines re-fetch and check the original promise in case
|
||||||
;; the first line of the let* caused it to be forced. For an example
|
;; the first line of the let* caused it to be forced. For an example
|
||||||
;; where this happens, see reentrancy test 3 below.
|
;; where this happens, see reentrancy test 3 below.
|
||||||
|
|
||||||
|
(define* (promise-visit promise #:key on-eager on-lazy)
|
||||||
|
(define content (promise-val promise))
|
||||||
|
(case (value-tag content)
|
||||||
|
((eager) (on-eager (value-proc content)))
|
||||||
|
((lazy) (on-lazy (value-proc content)))))
|
||||||
|
|
||||||
|
(set-record-type-printer! promise
|
||||||
|
(lambda (promise port)
|
||||||
|
(promise-visit promise
|
||||||
|
#:on-eager (lambda (value)
|
||||||
|
(format port "#<promise = ~s>" value))
|
||||||
|
#:on-lazy (lambda (proc)
|
||||||
|
(format port "#<promise => ~s>" proc)))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue