[plt-scheme] "identifier originates in a different module"

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun Jan 26 19:14:42 EST 2003

At Fri, 24 Jan 2003 19:52:28 -0500 (EST), Doug Orleans wrote:
> foo.scm:10:36: module: identifier originates in a different module at: x:foo 
> in: (define-values (x:foo) (invoke-unit (compound-unit (import number) (link 
> (unit-to-invoke (foo@ nu...
> 
> Can anyone shed light on this?  What is wrong with an identifier
> originating in a different module, and what should I do about it?

The error happens with a definition

 (module m ...
  (define x ...))

where the lexical scope associated with the identifier `x' is in some
other module, `m2'. In other words, it's a definition within `m' for an
identifier that claims to reside in `m2'.

This problem only happens with macros that make up names for
definitions, instead of using a part of the input syntax for the
defined name. The solution is to explicitly assign the defined
identifier the lexical context of the source definition.

Something like this:

  (define-syntax (define-foo stx)
    (syntax-case stx ()
      ((_ prefix number)
       #`(define-values/invoke-unit (#,(datum->syntax-object stx 'foo))
             foo@ prefix number))))

Matthew



Posted on the users mailing list.