[racket] local-expand and stop-lists?

From: Ryan Culpepper (ryan at cs.utah.edu)
Date: Fri Aug 12 13:58:11 EDT 2011

On 08/12/2011 11:37 AM, Sam Tobin-Hochstadt 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.

'#%plain-module-begin' also calls 'local-expand' to expose definitions, 
requires, etc. When I change Danny's sample code to use 
'#%plain-module-begin' instead of '#%module-begin', I get the same output.

In general, when a 'local-expand' happens inside of another 
'local-expand', the outer stop list is discarded. Since 
'#%plain-module-begin' effectively calls 'local-expand', I would expect 
the #'lift-to-toplevel stop list to never have any effect.

Unless you need to do some whole-module transformation, the simplest 
thing to do would be

      (my-module-begin form ...)
   -> (#%module-begin (lifting-aux form) ...)

where the 'lifting-aux' macro does local expansion, begin splicing, and 
handles 'lift-to-toplevel' forms.

If you do need to do whole-module transformation, you'll need to do 
something more complicated.

Ryan


Posted on the users mailing list.