diff --git a/module/srfi/srfi-45.scm b/module/srfi/srfi-45.scm index 51947700c..6f7ba7e04 100644 --- a/module/srfi/srfi-45.scm +++ b/module/srfi/srfi-45.scm @@ -39,7 +39,8 @@ eager 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)) @@ -76,3 +77,17 @@ ;; (*) 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 ;; 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 "#" value)) + #:on-lazy (lambda (proc) + (format port "# ~s>" proc)))))