[racket] Accessing lambda arguments in a macro

From: Daniel MacDougall (dmacdougall at gmail.com)
Date: Fri Sep 16 16:49:45 EDT 2011

Very cool, thanks for the ideas.

Daniel

On Fri, Sep 16, 2011 at 1:20 PM, Matthias Felleisen <matthias at ccs.neu.edu>wrote:

>
> Yes, I was thinking of naming the register explicitly too.
>
> On Sep 16, 2011, at 4:17 PM, Daniel MacDougall wrote:
>
> > I suppose that would work. Sam suggested on #racket that I include the
> name of the argument in the macro definition:
> >
> > (define-syntax-rule (foo bar form ...)
> >   ((lambda (bar) form ...) "ARG"))
> >
> > Then you could say:
> >
> > (foo bar
> >   ; Do stuff with bar here...
> >   )
> >
> > On Fri, Sep 16, 2011 at 1:12 PM, Matthias Felleisen <
> matthias at ccs.neu.edu> wrote:
> >
> >
> > Why not just store the arguments to lambda in some 'register' and ask for
> them?
> >
> >
> >
> >
> > On Sep 16, 2011, at 4:09 PM, Daniel MacDougall wrote:
> >
> > > In this example it should return "ARG".
> > >
> > > On Fri, Sep 16, 2011 at 1:08 PM, Matthias Felleisen <
> matthias at ccs.neu.edu> wrote:
> > >
> > >
> > > What should (foo bar) return?
> > >
> > >
> > > On Sep 16, 2011, at 3:46 PM, Daniel MacDougall wrote:
> > >
> > > > Is there any way to define a macro that expands out to a lambda, and
> then access the arguments passed to that lambda from outside the macro in
> the calling context?
> > > > Here's an example of what I mean:
> > > >
> > > > #lang racket
> > > >
> > > > (define-syntax-rule (foo form ...)
> > > >   ((lambda (bar) form ...) "ARG"))
> > > >
> > > > (foo "Hello") ; => returns "Hello"
> > > >
> > > > (foo bar)     ; => expand: unbound identifier in module in: bar
> > > >
> > > >
> > > > I'd like access to the "bar" argument on the last line. Is this
> possible with Racket macros?
> > > >
> > > > Thanks,
> > > > Daniel
> > > > _________________________________________________
> > > >  For list-related administrative tasks:
> > > >  http://lists.racket-lang.org/listinfo/users
> > >
> > >
> >
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110916/e86a9490/attachment.html>

Posted on the users mailing list.