Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#516 closed defect (fixed)

letrec fails when used in re-assigning top-level bindings

Reported by: Moritz Heidkamp Owned by: felix winkelmann
Priority: critical Milestone: 4.9.0
Component: compiler Version: 4.6.x
Keywords: compiler letrec top-level Cc:
Estimated difficulty:

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))

)

Change History (4)

comment:1 Changed 10 years ago by felix winkelmann

Priority: majorcritical

comment:2 Changed 10 years ago by felix winkelmann

Resolution: fixed
Status: newclosed

This should be fixed in experimental.

comment:3 Changed 10 years ago by felix winkelmann

Milestone: 4.7.04.8.0

Milestone 4.7.0 deleted

comment:4 Changed 9 years ago by felix winkelmann

Milestone: 4.8.04.9.0

Milestone 4.8.0 deleted

Note: See TracTickets for help on using tickets.