[plt-scheme] Unable to expand to a correct prefix in macro...

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Apr 24 20:11:55 EDT 2007

At Tue, 24 Apr 2007 13:35:45 -0700, "Yin-So Chen" wrote:
>   (define-syntax require-prefix
>     (lambda (stx)
>       (syntax-case stx ()
>         ((_ req-clause)
>          (with-syntax ((pref (datum->syntax-object stx (string->symbol
> "a:"))))
>          #`(require (prefix pref req-clause))))

The context of the `(prefix ...)' form determines the binding context
of the imports. So, you need to give the `(prefix ...)' part the
original context.

Here's one way to do it:

  (define-syntax require-prefix
    (lambda (stx)
      (syntax-case stx ()
        ((_ req-clause)
         (with-syntax ((pref-req-clause (datum->syntax-object 
                                         #'req-clause
                                         `(prefix a: ,#'req-clause)
                                         #'req-clause)))
           #'(require pref-req-clause)))
        ((_ req-clause rest ...)
         #'(begin
             (_ req-clause)
             (_ rest ...))))))


Matthew



Posted on the users mailing list.