[plt-dev] syntax/module-reader and #%module-begin

From: Sam TH (samth at ccs.neu.edu)
Date: Tue Dec 1 11:50:00 EST 2009

On Tue, Dec 1, 2009 at 11:29 AM, Eli Barzilay <eli at barzilay.org> wrote:
> On Dec  1, Sam TH wrote:
>> On Tue, Dec 1, 2009 at 10:59 AM, Eli Barzilay <eli at barzilay.org> wrote:
>> > On Nov 30, Stevie Strickland wrote:
>> >>
>> >> I've tried making the following change (surrounded by -----):
>> >>
>> >> -----
>> >> Index: collects/syntax/module-reader.ss
>> >> ===================================================================
>> >> --- collects/syntax/module-reader.ss  (revision 17113)
>> >> +++ collects/syntax/module-reader.ss  (working copy)
>> >> @@ -170,7 +170,11 @@
>> >>                                          (- (or (syntax-position modpath) (add1 pos))
>> >>                                             pos)))
>> >>                            v))]
>> >> -           [r `(,(tag-src 'module) ,(tag-src name) ,lang . ,body)])
>> >> +           [wrapped-body (let ([wrapped `(#%module-begin . ,body)])
>> >> +                           (if stx?
>> >> +                               (datum->syntax #f wrapped all-loc)
>> >> +                               wrapped))]
>> >> +           [r `(,(tag-src 'module) ,(tag-src name) ,lang ,wrapped-body)])
>> >>        (if stx? (datum->syntax #f r all-loc) r)))
>> >>
>> >>    (define (wrap lang port read modpath src line col pos)
>> >> -----
>> >
>> > Isn't it better to do the wrapping only when `#%module-begin' is not
>> > there?
>>
>> What would this mean?  Looking for the symbolic name
>> '#%module-begin?
>
> Yes.
>
>
>> That seems like it adds another special case, where the benefit of
>> the change is to remove such special cases, especially since it
>> wouldn't help if you wrote #%plain-module-begin instead.
>
> It is already a special case -- it's a symbolic name that gets added.

Right, but currently the rule for #%module-begin insertion is
complicated.  With this change, it would become simpler - if you use
#lang, #%module-begin is always inserted.  With your suggestion, the
rule grows a special case.

> (IIRC, `#%plain-module-begin' is not a special case, and intended only
> to be provided from a language as `#%module-begin'.)

No, you can certainly write

(module m scheme (#%plain-module-begin 'x 'y 'z))

Thus, if you wanted to support that with #lang as well, you could add
the symbol '#%plain-module-begin to this special case as well.

> The reason I've asked this is that a reader that adds `#%module-begin'
> will be broken if it's added by `syntax/module-reader'
> unconditionally.

That is a potential problem.  Are there any languages that do that right now?

-- 
sam th
samth at ccs.neu.edu


Posted on the dev mailing list.