Both CHICKEN 6 and CHICKEN 5 with the r7rs egg exhibit unexpected behavior with the following set of libraries (this file is referred to as "tmp.scm"):

        (define-library (hascheme prelude)
         (import (scheme base) (scheme lazy))
         (export hs:promise? hs:delay hs:delay-force hs:force)
         (begin
           (define-record-type <hascheme-promise>
             (%hascheme-promise promise)
             hs:promise?
             (promise %get-raw-promise))
           (define-syntax hs:delay-force
             (syntax-rules ()
               ((_ expr)
                (%hascheme-promise (delay-force expr)))))
           (define-syntax hs:delay
             (syntax-rules ()
               ((_ expr)
                (%hascheme-promise (delay expr)))))
           (define (hs:force promise)
             (if (hs:promise? promise)
                 (force (%get-raw-promise promise))
                 promise))))
        
        (define-library (my-other-library)
         (import (scheme base)
                 (rename (hascheme prelude)
                         (hs:delay delay)
                         (hs:force force)
                         (hs:delay-force delay-force)
                         (hs:promise? promise?)))
         (export delay force delay-force promise? !)
         (begin
           (define ! force)))

When the following is done in a REPL:

    (load "tmp.scm")
    (import (hascheme prelude))
    (define x 10)
    (hs:force (hs:delay (set! x 100)))
    x

one gets the intended result 100.

But if the following is done in a REPL:

    (load "tmp.scm")
    (import (my-other-library))
    (define x 10)
    (force (delay (set! x 100)))
    x

Then x is not changed, even though "force" and "delay" should be exactly "hs:force" and "hs:delay".

The behavior likely occurs in compiled code too. The project from which I pulled this reduced example exhibits the same errors when compiled, but I have not tried the minimal example compiled.

-- Peter McGoron

Reply via email to