[racket] local-expand and stop-lists?
On Fri, Aug 12, 2011 at 1:39 PM, Danny Yoo <dyoo at cs.wpi.edu> wrote:
> On Fri, Aug 12, 2011 at 1:37 PM, Sam Tobin-Hochstadt <samth at ccs.neu.edu> wrote:
>> On Fri, Aug 12, 2011 at 1:25 PM, Danny Yoo <dyoo at cs.wpi.edu> wrote:
>>>
>>> In which the first three lines are coming from compile-time, and I see
>>> that my lift-to-toplevel macro is firing off, even though I placed it
>>> in the stop-list of local-expand.
>>
>> What's happening here is that the `#%module-begin' binding from
>> `racket/base' calls `local-expand' on each of its forms, to determine
>> whether its an expression or not. This implements the printing of
>> top-level expressions. If you replace `#%module-begin' with
>> `#%plain-module-begin', you should see the desired behavior.
>
> Ha ha; that's tricky! Thanks! Can something about this be included
> in the documentation of local-expand?
Alternately, if you want to keep the printing behavior of
#%module-begin, then local-expand each body element directly, and wrap
them in #%module-begin after the fact. This is more work (e.g. manual
splicing of begin), but doesn't require knowing how #%module-begin or
#%plain-module-begin are implemented. In general, with local-expand,
it is best not to make assumptions about how sub-parts of a form are
expanded. If you want to interpret something specially, expanding it
without wrappers is the most predictable way.
--Carl