[racket] Review request: Partially expanding to make "blue boxes"

From: Greg Hendershott (greghendershott at gmail.com)
Date: Fri Aug 15 21:49:47 EDT 2014

> (dynamic-require target-module 0)
> (parameterize ([current-namespace (module->namespace target-module)])
>   (expand-once a-module-level-stx))
>
> Where a-module-level-stx is a form inside #%module-begin.

Thanks for the idea!

Unfortunately:

1. (expand-once #'(provide foo)) will fail with e.g. "(provide foo):
not at module level". I don't think I can use expand-once on
individual #%module-begin expressions.

2. Besides, I don't think expand-once will necessarily expand
"definer" macros sufficiently to produce the forms I want to see
(define, provide, define/contract, provide/contract). I think I really
do need to use local-expand; it seems like the tool for this job.

Now, local-expand complains if it's not used in an
expander/transformer[^1]. It complains if I call it from phase 0 code
on a syntax object. That stumped me. Then I had the idea to insert a
macro definition at the start of the module, so that I do call
local-expand in the context it wants. Whether that's OK-clever or
horrible-clever, is I guess part of the feedback I'm looking for. :)

[^1]: The local-expand docs actually say: "This procedure must be
called during the dynamic extent of a syntax transformer application
by the expander or while a module is visited". The latter possibility
sounds promising, but I don't understand how I would insinuate myself
into the process of visiting a module. Would this be via overriding
current-compile then chaining to the original?

Posted on the users mailing list.