[racket-dev] Trouble with state, submodules, and module-begin

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Jun 25 18:47:36 EDT 2012

At Mon, 25 Jun 2012 17:50:27 -0400, Sam Tobin-Hochstadt wrote:
> The problem (I
> think) is that the implicit `require` of `(submod "..")` happens
> *before* the expansion of `#%module-begin` inside the submodule.

That's the same for a top-level module M whose initial language is some
other module L, right? The require of `L' happens before the
`#%module-begin' expansion in `M'... and it can't be any other way,
because `#%module-begin' comes from `L'.

> The
> key bit of code is the residual snippet left in the outer module:
>          (begin-for-syntax
>              (when (unbox is-typed?)
>                (set-box! type-env 1)))
> Currently, in TR, the code in the begin-for-syntax is unconditional,
> and therefore it gets re-run in the store used for expanding the inner
> submodule.  However, if I add the `when`, then the `set-box!` doesn't
> happen, and the expansion of `m` fails.  I'd like to be able to add
> this conditional, so I'd like to change the order of effects slightly
> here.

I see what you mean, but I don't think it makes sense to change the
order of things in the way that you're suggesting. I don't have any
immediate ideas, but I'll think about it more.

Posted on the dev mailing list.