[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 
                                         `(prefix a: ,#'req-clause)
           #'(require pref-req-clause)))
        ((_ req-clause rest ...)
             (_ req-clause)
             (_ rest ...))))))


Posted on the users mailing list.