[plt-scheme] Context-specific namespaces

From: Lauri Alanko (la at iki.fi)
Date: Fri Jan 6 12:15:55 EST 2006

Consider the following:

Welcome to MzScheme version 300.3, Copyright (c) 2004-2006 PLT Scheme Inc.
> (define-struct foo (x))
> (define foo make-foo)
> (define-struct (bar foo) (y))
stdin::46: define-struct: parent struct type not defined at: foo in: (define-struct (bar foo) (y))

Now, this is annoying. One foo is only used in an expression context,
the other is only used in a structure type context, and these two are
wholly disjoint. Why, then, must the structure type identifiers inhabit
the same namespace that is used by ordinary variables and macros?

The same problem arises with e.g. the regexp combinators in the
parser-tools lexer. The bindings in lex-sre.ss shadow various standard
operators, and therefore must be imported with a prefix. Even though
the regexp combinators are again used in a quite different context from
ordinary identifiers.

So: is there some way to attach syntactic information to identifiers
that syntactic extensions could use _without_ actually creating an
ordinary binding for that identifier?

An obvious low-tech solution of course presents itself: prefixes. That
is, the above define-struct would actually bind the identifer
*some-magic-prefix*foo and the same prefix would be added during syntax
expansion in contexts where a structure type identifier is expected. 
However, this is just an unreliable kludge, and given the superbly
sophisticated syntax and scope machinery in mzscheme, I'd expect there
to be a better way to do this. Is there?



Posted on the users mailing list.