diff --git a/contrib/20.r7rs/scheme/lazy.scm b/contrib/20.r7rs/scheme/lazy.scm index 7378c384..0df49444 100644 --- a/contrib/20.r7rs/scheme/lazy.scm +++ b/contrib/20.r7rs/scheme/lazy.scm @@ -24,9 +24,12 @@ (if (promise-done? promise) (promise-value promise) (let ((new-promise ((promise-value promise)))) - (set-promise-done! promise (promise-done? new-promise)) - (set-promise-value! promise (promise-value new-promise)) - (force promise)))) + (if (promise-done? promise) + (promise-value promise) + (begin + (set-promise-done! promise (promise-done? new-promise)) + (set-promise-value! promise (promise-value new-promise)) + (force promise)))))) (define (make-promise obj) (if (promise? obj) diff --git a/contrib/20.r7rs/t/r7rs.scm b/contrib/20.r7rs/t/r7rs.scm index f329d781..9334ad6e 100644 --- a/contrib/20.r7rs/t/r7rs.scm +++ b/contrib/20.r7rs/t/r7rs.scm @@ -363,7 +363,15 @@ (force x) (promise? x))) - +(let () + (define flag #f) + (define p (delay (if flag + 'ok + (begin + (set! flag #t) + (force p) + 'ng)))) + (test 'ok (force p))) (define radix