Summary
letrec fails when used in re-assigning top-level bindings
Metadata
- Id: 3f8c91314deea5cbee40550d339a7bc31a4bb43c
- Trac id: 516
- Type: defect
- Reporter: syn
- Owner: felix
- Cc:
- Status: closed
- Component: compiler
- Estimated difficulty:
- Resolution: fixed
- Priority: critical
- Milestone: 4.9.0
- Version: 4.6.x
- Changetime: 2012-09-24 21:47:48 UTC
- Created: 2011-02-25 22:35:02 UTC
- Keywords: compiler letrec top-level
Description
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))
)
Changes and comments
[2011-03-01 14:43:40 UTC] felix changed priority from major to critical
[2011-03-14 06:58:52 UTC] felix changed status from new to closed
[2011-03-14 06:58:52 UTC] felix set resolution to fixed
[2011-03-14 06:58:52 UTC] felix wrote:
This should be fixed in experimental.
[2011-06-01 09:00:41 UTC] felix changed milestone from 4.7.0 to 4.8.0
[2011-06-01 09:00:41 UTC] felix wrote:
Milestone 4.7.0 deleted
[2012-09-24 21:47:48 UTC] felix changed milestone from 4.8.0 to 4.9.0
[2012-09-24 21:47:48 UTC] felix wrote:
Milestone 4.8.0 deleted