[plt-scheme] Unable to expand to a correct prefix in macro...
Just want to verify a quick point w.r.t the solution:
My understanding is that if an identifier is "known" then it would evaluate
to the correct form - for example:
(lambda (stx)
(syntax-case stx ()
((_ foo ...)
#'(begin
(_ foo ...)))))
The begin keyword is "okay" (without having to provide context) because it
is already an known identifier. But if I am to generate my own name then I
need to use the datum->syntax-object binding.
So why isn't '(provide ...) "okay"?
Thanks,
yinso
On 4/24/07, Yin-So Chen <yinso.chen at gmail.com> wrote:
>
> 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...
--
http://www.yinsochen.com
...continuous learning...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070424/2d1bdb9c/attachment.html>