Re: Corrected reference implementation
Andre van Tonder 22 Apr 2005 13:21 UTC
On Fri, 22 Apr 2005, Matthew D Swank wrote:
> ...
> there is the following construct:
>
> 1. (let* ((promise* (stream-promise ((s:promise-content content))))
> (content (unbox promise)))
>
> however, since 'content' is being bound to (unbox promise), and not
> (unbox promise*),
> the 'let*' in 1. is superfluous.
No, because the evaluation of ((s:promise-content content)) may have a side
effect that changes the original promise. I believe this also answers your
subsequent questions. All this is explained in the SRFI-45 "Primitives for
Expressing Iterative Lazy Algorithms" document. In particular, the following
code there should have the indicated behaviour:
(define q
(let ((count 5))
(define (get-count) count)
(define p (delay (if (<= count 0)
count
(begin (set! count (- count 1))
(force p)
(set! count (+ count 2))
count))))
(list get-count p)))
(define get-count (car q))
(define p (cadr q))
(get-count) ; => 5
(force p) ; => 0
(get-count) ; => 10
The alternative you suggest was in fact
what appeared in initial versions of SRFI-45, found to be incorrect, and
corrected.
Regards
Andre van Tonder