Summary

strange behaviour with define-record and modules

Metadata

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

Changes and comments

[2012-08-27 20:41:02 UTC] sjamaan changed status from new to closed

[2012-08-27 20:41:02 UTC] sjamaan set resolution to worksforme

[2012-08-27 20:41:02 UTC] sjamaan wrote:

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

 #!scm
 (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.

[2012-08-27 21:43:40 UTC] felix wrote:

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.

[2012-08-28 15:59:09 UTC] megane wrote:

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

[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