letrec fails when used in re-assigning top-level bindings
The following program works as expected when interpreted, i.e. it prints "hey". However, when compiled it prints #<unbound value>
or, when compiled as a shared object, it signals unbound variable: foo#bar
. The comments in the program point out two ways of making it work when compiled. It seems that the optimizer removes the original binding of bar
when letrec
is used for its redefinition. Putting some top-level code between definition and re-definition prevents that as well as replacing letrec
with let*
. Note that the module form can be left out to reproduce the problem, too.
(module foo
(bar)
(import chicken scheme)
(define bar 'hey)
;; uncommenting the next line makes it work when compiled
;; (print 'some-top-level-expression)
(set! bar
;; changing the letrec to a let* also makes it work when compiled
(letrec ((baz bar)
(qux (lambda () baz)))
qux))
(print (bar))
)
Change History (4)
Priority: |
major →
critical
|
Resolution: |
→ fixed
|
Status: |
new →
closed
|
This should be fixed in experimental.