[plt-scheme] re: another macro+module anomaly

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Apr 7 10:36:45 EDT 2003

At Sun, 6 Apr 2003 21:46:21 EDT, Benderjg2 at aol.com wrote:
> Several months ago I posted a query regarding matching literals in macros, 
> for which the answer was to use syntax-case* with 
> 'module-or-top-identifier=?'. For my problem at the time, this solved the 
> problem.
> But a curious point for me, was that I had a problem symbols which were, also 
> bound MzScheme _values_. 'or' and 'and' seemed to work just fine. I think, 
> mistakenly, I concluded that this was a problem for value bindings, but not 
> syntactic bindings.

Instead of value vs. syntax, the difference is whether the name at the
top-level refers to an import or a global variable. MzScheme "require"s
the `mzscheme' module in the initial namespace so that each syntax
export of `mzscheme' becomes a top-level import, while each value
export of `mzscheme' is copied to a fresh global variable.

> I say this because, while 'or' and 'and' work just fine, 
> with-or-without the use of 'module-or-top-identifier=?', "class" fails even 
> with the use of 'module-or-top-identifier=?'. Now I am just confused ;)
> The module:
> (module ex mzscheme
>   (provide test)
>   (require-for-syntax (lib "stx.ss" "syntax"))
> [...]

I suspect that you tested this module in a context that imports (lib
"class.ss"). If so, if you import (lib "class.ss") into the above
module, it will work the way you expect.

Depending on your application, symbol equality may be fine. A good rule
of thumb is that `module-identifier=?' or `module-to-top-identifier=?'
should be used when the keyword appears in an expression position. For
example, this is why `cond' checks for `else' using
`module-identifier=?'. In contrast, `require' checks for `lib' with
symbol equality.


Posted on the users mailing list.