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

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun Apr 29 05:16:35 EDT 2007

At Thu, 26 Apr 2007 21:33:53 -0400, Jon Rafkind wrote:
> Matthew Flatt wrote:
> > 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.
> >
> >   
> How does one know when a special form requires the original context of 
> the syntax to do its job properly? Are there special rules?

Binding forms need the original context, at least if the bindings are
to be visible in the original context.

Exactly which part of a binding form needs the context varies by the
form. In the usual case, like `define', the binding is specially named
by an identifier, and so the identifier needs the context. The
`require' form is unusual in this respect, because the imported names
usually are not listed explicitly. More or less arbitrarily, then, the
context for the bindings derived from a `prefix' clause use the context
of the whole clause.

Matthew



Posted on the users mailing list.