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

From: Stevie Strickland (sstrickl at ccs.neu.edu)
Date: Mon Nov 30 15:43:00 EST 2009

On Nov 30, 2009, at 2:02 PM, Matthew Flatt wrote:
> This sounds like a good idea.
> The special treatment of a single form in a module body allows
> (module m name (#%module-begin ..))
> to expand to itself, instead of
> (module m name (#%module-begin (#%module-begin ..)))
> We could have defined `module' in other ways so that a module can
> expand to itself, and maybe some of the other ways would have been
> better. In any case, that's not a concern at the `#lang' level, so I
> think it's fine for `syntax/module-reader' to add `#%module-begin'.

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))
-           [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)

So that breaks two things.  One is the searching for provide/doc forms in tool-lib.ss, and that's fixed thus (same separator):

Index: collects/drscheme/private/tools.ss
--- collects/drscheme/private/tools.ss	(revision 17113)
+++ collects/drscheme/private/tools.ss	(working copy)
@@ -316,6 +316,8 @@
        (let loop ([sexp full-sexp])
          (match sexp
+           [`((#%module-begin ,body ...))
+            (loop body)]
            [`((provide/doc (,x ,name ,ctc ,other ...) ...) ,rest ...)
             #`(let #,(map (λ (name ctc) 
                             (with-syntax ([name (datum->syntax #'tool-name name)]

But the other failure happens only during setup-plt (as far as I can tell) with files that use "#lang scribble/lp".  They run fine in mzscheme/mred, but they fail to compile during setup-plt with, for example:

chat-noir/chat-noir-literate.ss:1:0: #%module-begin: allowed only around a module body in: (#%module-begin "\n" "\n" (require (for-label scheme/math) scheme/math games/scribblings/common) "\n" "\n" (gametitle* "Chat Noir" "chat-noir" "Puzzle Game" #:style (quote (toc))) "\n" "\n" (author (link "http://www.eecs.northwestern.edu/~robby" "Robby ...

I've looked at the expansion of these files via the macro debugger on a clean checkout, and that does seem to be what they expand to when they successfully run, so I'm not sure what's going on here.  It confuses me that these run fine, and I can compile them with mzc, but they fail to compile during setup-plt.  Is there something I'm overlooking?


Posted on the dev mailing list.