Re: Corrected reference implementation Matthew D Swank (22 Apr 2005 09:03 UTC)
Re: Corrected reference implementation Andre van Tonder (22 Apr 2005 13:22 UTC)
Re: Corrected reference implementation Matthew D Swank (22 Apr 2005 14:52 UTC)
Re: Corrected reference implementation Andre van Tonder (22 Apr 2005 16:08 UTC)

Re: Corrected reference implementation Matthew D Swank 22 Apr 2005 09:03 UTC

In:

(define (srfi-40:force promise)
  (let ((content (unbox promise)))
    (case (s:promise-kind content)
      ((eager) (s:promise-content content))
      ((lazy)
       (let* ((promise* (stream-promise ((s:promise-content content))))
              (content  (unbox promise)))
         (if (not (eqv? 'eager (s:promise-kind content)))
             (begin
               (set-s:promise-kind! content (s:promise-kind (unbox
promise*)))
               (set-s:promise-content! content (s:promise-content (unbox
promise*)))
               (set-box! promise* content)))
         (srfi-40:force promise))))))

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.

Also 'promise has already been bound to (unbox promise)
at the beginning of the function:

2. (define (srfi-40:force promise)
     (let ((content (unbox promise)))

So isn't the binding in 1. a noop?

Finally, since (eqv? (s:promise-kind content) 'lazy) is already known by
the time 1. is evaluated,
isn't the subsequent test:

3. (if (not (eqv? 'eager (s:promise-kind content)))

also superfluous?

Assuming the semantics of force are correct (which they seem to be), I
believe it should look like:

(define (srfi-40:force promise)
  (let ((content (unbox promise)))
    (case (s:promise-kind content)
      ((eager) (s:promise-content content))
      ((lazy)
       (let ((promise* (stream-promise ((s:promise-content content)))))
         (set-s:promise-kind! content (s:promise-kind (unbox promise*)))
         (set-s:promise-content! content (s:promise-content (unbox
promise*)))
         (set-box! promise* content)
         (srfi-40:force promise))))))

Am I missing something?

Humbly,

Matt

--
"You do not really understand something unless you can explain it to your grandmother." $(G!7(B Albert Einstein.