Thanks to both of you, it is exactly what I was trying to do.

Stefano

Il giorno ven 22 feb 2019 alle ore 18:37 Matthias Felleisen <
[email protected]> ha scritto:

>
> And that’s better of course because you pick up the lexical scope, which
>
>   (let ([x 4]) [(my-macro x) 1 2])
>
> shows.
>
>
>
> > On Feb 22, 2019, at 1:26 PM, Sam Caldwell <[email protected]> wrote:
> >
> > You can also do this with syntax-local-introduce to remove x's use-site
> scope*:
> >
> > #lang racket
> >
> > (require (for-syntax syntax/parse))
> >
> > (define-syntax (my-macro stx)
> >    (syntax-parse stx
> >      [(_ x:id)
> >       #:with x- (syntax-local-introduce #'x)
> >       #'(lambda (a b) x-)]))
> >
> > ((my-macro a) 1 2)
> > ;; 1
> >
> > ((my-macro b) 1 2)
> > ;; 2
> >
> > (define x 3)
> > ((my-macro x) 1 2)
> > ;; 3
> >
> >
> >
> > -Sam
> >
> > * well, I think that's what's going on.
> >
> > On Fri, Feb 22, 2019 at 1:21 PM Matthias Felleisen <
> [email protected]> wrote:
> >
> >
> > > On Feb 22, 2019, at 1:08 PM, Stefano Lande <[email protected]> wrote:
> > >
> > > Dear all,
> > >
> > > first of all, I might being misusing the terminology. Sorry about it.
> > >
> > > I would like to write a macro that gets an identifier and return its
> value in the new lexical scope created by the macro.
> > > For example:
> > >
> > > > (define-syntax (my-macro stx)
> > >    (syntax-parse stx
> > >      [(_ x:id)  #'(lambda (a b) x) ]))
> > >
> > >
> > > > ((my-macro a) 1 2)
> > > 1
> > >
> > > >((my-macro b) 1 2)
> > > 2
> > >
> > >
> > >
> > > my-macro as above of course would not work. Is possible to receive an
> identifier, strip the lexical context, and evaluate it in the context of
> (lambda (a b) body) ?
> >
> >
> > Here is one way to get your macro:
> >
> > #lang racket
> >
> > (require (for-syntax syntax/parse))
> > (require (for-syntax racket/syntax))
> >
> > (define-syntax (my-macro stx)
> >   (syntax-parse stx
> >     [(_ x:id)
> >      #:with a #'a
> >      #:with y (datum->syntax #'a (syntax-e #'x))
> >      #`(lambda (a b) y)]))
> >
> > [(my-macro a) 1 2]
> > [(my-macro b) 1 2]
> > (define x 3)
> > [(my-macro x) 1 2]
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected].
> > For more options, visit https://groups.google.com/d/optout.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to