Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#909 closed defect (worksforme)

strange behaviour with define-record and modules

Reported by: megane Owned by:
Priority: major Milestone: 4.9.0
Component: core libraries Version: 4.8.x
Keywords: modules Cc:
Estimated difficulty:

Description

Might not be define-record specific.

(module
 m1
 (make-foo)
 (import chicken scheme)

 (define-record foo a)

 (let [(make* make-foo)]
   (set! make-foo
	 (lambda ()
	   (make* 1)))))

(module
 m2
 ()
 (import chicken scheme)
 (import m1) ; <- remove this and everything works

 (define-record foo a))

(import m1)
(print (make-foo))

;; Error: bad argument count - received 0 but expected 1: #<procedure (make-foo a)>

Change History (4)

comment:1 Changed 9 years ago by sjamaan

Resolution: worksforme
Status: newclosed

I think this is normal, expected behavior. It's functionally equivalent to:

(module m1 (blabla) 
  (import chicken scheme)
  (define blabla 1))

(module m2 (blabla)
  (import chicken scheme m1)
  (define blabla 2))

;;; This will show you: Warning: redefinition of imported value binding: blabla

(import m1)
(print blabla)
;; 2 is printed

Your test example can be "fixed" by either omitting or renaming make-foo from the import specifier for m1. But note that this isn't currently going to work, because record type names must be globally unique (this is arguably a bug which we've tried to fix but the initial fix broke more than it fixed, so we had to revert it)

If you disagree this is normal, please re-open this ticket.

comment:2 Changed 9 years ago by felix winkelmann

It is important to remember that modules do not create a separate binding environment. Any imported identifier can be re-assigned and the assignment will modify the global binding (define and set! are equivalent at the global level). The module system just renames and resolves global identifiers.

comment:3 Changed 9 years ago by megane

Thanks for the explanations. I don't know what I was thinking.

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.