> On Feb 22, 2019, at 1:08 PM, Stefano Lande <lande...@gmail.com> 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 racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to