[plt-scheme] depth of macro expansion in module during module require?

From: Yin-So Chen (yinso.chen at gmail.com)
Date: Tue Apr 17 17:29:06 EDT 2007

Hi all -

I wrote a few macros that are meant to be syntactic sugars for servlet
modules but appear to run into macro expansion problems that appears to be a
depth program, or a conflict with macro provide or something else... not
sure the actual causes.

What I am trying to do is to write something like following:

(module webtest1 mzscheme
  (require "syntax-util.scm") ; contains the syntactic sugar macros
  (servlet ; this is the form that will expand to the 3 required form for
servlets - interface-version is hard coded; need to define time-out & main
   (time-out +inf.0)
   (main
    `(p "hello world")))
  )

The goal is to have it expand to:

(module webtest1 mzscheme
  (require "syntax-util.scm")
  (define interface-version 'v1)
  (define timeout +inf.0)
  (define (start initial-request)
    `(p "hello world"))
  (provide (all-defined)))

I expanded my macros manually and it seem to produce the form above without
problems.  The actual expansion turns out to be:

> (syntax-object->datum (expand '(module webtest1 mzscheme
                 (require syntax-util)
                 (servlet
                  (time-out +inf.0)
                  (main
                   `(p "hello world"))))))

(module webtest1 mzscheme
  (#%plain-module-begin
   (require-for-syntax mzscheme)
   (require syntax-util)
   (define-values (timeout) (#%datum . +inf.0))
   (define-values (start) (lambda (initial-request) '(p "hello world")))
   (define-values (interface-version) 'v1)
   (provide (all-defined))))

Which is the same when I manually expand the module with direct definition
of timeout/start/interface-version.

> (syntax-object->datum (expand  '(module webtest1 mzscheme
                 (require syntax-util)
                 (begin
                   (define timeout +inf.0)
                   (define (start initial-request)
                     `(p "hello world"))
                   (define interface-version 'v1)
                   (provide (all-defined))))))

(module webtest1 mzscheme
  (#%plain-module-begin
   (require-for-syntax mzscheme)
   (require syntax-util)
   (define-values (timeout) (#%datum . +inf.0))
   (define-values (start) (lambda (initial-request) '(p "hello world")))
   (define-values (interface-version) 'v1)
   (provide (all-defined))))

The expansions appear to be the same, but when I require the first module, I
was only able to get the definition for interface-version, but timeout and
start are undefined.  Why would this be the case?

The macros in question are following:

(module syntax-util mzscheme
  (provide (all-defined))

  (define-syntax (time-out stx)
    (syntax-case stx ()
      ((_ value)
       #'(define timeout value))))

  (define-syntax (main stx)
    (syntax-case stx ()
      ((_ body ...)
       #`(define start
           (lambda (initial-request)
             body ...)))))

  (define-syntax servlet
    (lambda (stx)
      (syntax-case stx ()
        ((_ body ...)
         #`(begin
             body ...
             (define interface-version 'v1)
             (provide (all-defined))
             )))))
  )

Thanks,
yinso

-- 
http://www.yinsochen.com
...continuous learning...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070417/5b1397cd/attachment.html>

Posted on the users mailing list.