Recently, I whined a bit about Racket's namespaces and modules being too "opaque" (http://arclanguage.org/item?id=14029). This got me looking around at just how opaque they were, and I ended up figuring out how to do a lot of the stuff I wanted to do. As part of the process of figuring this stuff out, I've put together some utilities and pushed them to Anarki as lib/ns.arc. These utilities should make Racket's modules and namespaces much less of a pain to use. For instance, modules aren't exactly first-class in Racket--you have to kind of name them, attach them to module registries (which can only be interacted with by way of namespaces that share them), and then require them--but ns.arc's module creation utilities use gensyms for the module names, put them all in a single module registry, and wrap up references to the modules using a 'module tagged type, so they're effectively first-class after all.
The ns.arc utilities aren't especially well-rounded yet; there's currently no utility for actually requiring a 'module value in the current namespace, and there's no utility for getting a Racket module given a Racket module path. However, those should be easy things to add. The code covers most of the hard parts, and it should act as a good cheat sheet for implementing whatever hard parts are left over.
One especially hard part, which this doesn't begin to cover, is to make it easy to compose Arc programs. While ns.arc may help you manipulate Racket modules and namespaces from Arc, but it's hardly an Arc module system. The leading comment in ns.arc says it best.
Meanwhile, this adventure revealed some necessary (IMO) changes to ac.scm. The comment for the new 'arc-exec function says that best, and it's short enough to quote here:
///
"To make namespace and module handling more seamless (see lib/ns.arc), we use Racket's 'set! even for undefined variables, rather than using 'namespace-set-variable-value! for all Arc globals. This makes it possible to parameterize the value of 'current-namespace without getting odd behavior, and it makes it possible to assign to imported module variables and use assignment-aware syntax transformers (particularly those made with Racket's 'make-set!-transformer and 'make-rename-transformer).
"However, by default 'set! is disallowed when the variable is undefined, and we have to use the 'compile-allow-set!-undefined parameter to go against that default. Rather than sprinkling (parameterize ...) forms all over the code and trying to keep them in sync, we put them all in this function ['arc-exec], and we use this function instead of 'eval when executing the output of 'ac.
"In the same spirit, several other uses of 'namespace-variable-value and 'namespace-set-variable-value! have been changed to more direct versions ((set! ...) forms and direct variable references) or less direct versions (uses of full 'arc-eval) depending on how their behavior should change when a module import or syntax obstructs the original meaning of the variable. Some have instead been kept around, but surrounded by (parameterize ...) forms so they're tied the main namespace. Another utility changed in this spirit is 'bound?, which should now be able to see variables which are bound as Racket syntax."
\\\
With any luck I haven't wrecked people's code too much, and hopefully someone can figure out what I've put together and take advantage of it for some bigger purpose. ^_^