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

From: Yin-So Chen (yinso.chen at gmail.com)
Date: Tue Apr 24 20:40:36 EDT 2007

Thanks!! I was scratching my head trying to figure out where things went
wrong and went down the define-macro path... thanks for pointing out my
misunderstanding ;)

Very appreciated ;)

yinso

On 4/24/07, Matthew Flatt <mflatt at cs.utah.edu> 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.
>
> 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
>
>


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

Posted on the users mailing list.