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

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Tue Apr 17 18:33:53 EDT 2007

Hi Yin-So,

Here is one way to do it:

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

   (define-syntax servlet
     (lambda (stx)
       (syntax-case stx ()
         ((_ body ...)
          (with-syntax ([time-out (datum->syntax-object stx 'time-out)]
                        [main     (datum->syntax-object stx 'main)])
                (define-syntax (time-out stx)
                  (syntax-case stx ()
                    ((_ value)
                         (define timeout value)
                         (provide timeout)))))
                (define-syntax (main stx)
                  (syntax-case stx ()
                    [(_ body1 (... ...))
                     #'(define start
                         (lambda (initial-request)
                           body1 (... ...)))]))
                body ...
                (define interface-version 'v1)
                (provide (all-defined))

    (require syntax-util)

  (module webtest1 mzscheme
    (require syntax-util)
     (time-out +inf.0)
     (main `(p "hello world"))

  (require webtest1)


I moved the definitions of time-out and main into the expansion of 
servlet, since they need to be in the scope of the forms of body ... .
Note that when expanding into ... one needs to write (... ...).

Also, to provide a name such as timeout, the provide form must have
the same syntactic context as the definition. The easiest way to ensure
this is, to put a provide-clause next to the definition.

Jens Axel Søgaard

Jens Axel Søgaard

Posted on the users mailing list.