[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reentrancy-detecting, faster implementation



On Oct 19, Andre van Tonder wrote:
> Here is another safe-for-space version of srfi-45 promises that
> detects reentrant promises and should be faster.
> [...]
>    (define (dispatch node)
>      (let ((type    (car node))
>            (content (cdr node)))
>        (set-car! node 'shared)     ; maintain any sharing by
>        (set-cdr! node root-node)   ; pointing back to root
>        (case type
>          ((lazy)   (dispatch (content)))
>          ((value)  (set-car! root-node 'value)   ; overwrite root at end
>                    (set-cdr! root-node content)
>                    content)
>          ((shared) (dispatch content))
>          (else     (error "Invalid promise")))))

One problem in the above: it should also catch a hole and throw a
reentrant error, otherwise:

  (letrec ([a (lazy a)]) (force a))

produces a bad error message.  (I will post a version that fixes this,
(and adds more) soon.)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!