[racket] macro for define-values?

From: Laurent (laurent.orseau at gmail.com)
Date: Tue Feb 25 02:57:15 EST 2014

Eric's solution is probably the best one, but using `define-values` can
still be made a bit simpler:
(define-syntax-rule (ref name ...)
  (define-values (name ...) (values (void 'name) ...)))
since `void` takes a variable number of arguments and discards them.

Laurent

On Tue, Feb 25, 2014 at 8:16 AM, Eric Dobson <eric.n.dobson at gmail.com>wrote:

> Does this do what you want? (Note its untested.)
>
> (define-syntax-rule (ref name ...)
>   (begin
>     (define name (void)) ...))
>
> Using define-values is tricky as you saw, because you need to refer to
> name in the body to get the right duplication but then not use it.
>
> On Mon, Feb 24, 2014 at 10:23 PM, Kevin Forchione <lysseus at gmail.com>
> wrote:
> > I'm trying to code a macro that will define a variable number of
> identifiers. What I want is something like:
> >
> >         (ref foo bar baz ...)
> >
> > and assign them an initial value of #<void>. The kludge I've come up
> with works, but there must be a better way to do this:
> >
> > (define-syntax-rule (ref name ...)
> >   (define-values (name ...) (values ((λ (name) (void)) #f) ...)))
> >
> >>(ref foo bar baz)
> >>foo
> > #f
> >
> > Thanks!
> >
> > -Kevin
> > ____________________
> >   Racket Users list:
> >   http://lists.racket-lang.org/users
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140225/1870b53d/attachment-0001.html>

Posted on the users mailing list.