Are you sure that `begin` doesn't suffice for your needs? It has a somewhat
unintuitive scoping behavior. From the docs [1]

The begin form is special at the top level, at module level, or as a body
after only internal definitions. In those positions, instead of forming an
expression, the content of begin is spliced into the surrounding context.

Example:

> (let ([curly 0])
    (begin
      (define moe (+ 1 curly))
      (define larry (+ 1 moe)))
    (list larry curly moe))

'(2 0 1)

- Sam Caldwell

[1] http://docs.racket-lang.org/guide/begin.html

On Thu, Jun 22, 2017 at 3:40 PM, Sam Waxman <[email protected]> wrote:

> Hello,
>
> It's simple enough to write a macro that defines something.
>
> (define-syntax-rule (my-define name binding)
>    (define name binding))
>
> But what if I would like to define multiple things? I.e.
>
> (define-syntax-rule (my-multiple-define name ... binding ...)
>    (define name binding) ...)
>
> The above is no good, because define-syntax-rule expects only one body to
> be returned, not multiple. Wrapping the defines in begin wouldn't work,
> because then they'd only be able to be accessed in the scope of that begin
> (when, in actuality, I want the rest of the code to access them, like they
> would be able to in the first example).
>
> Similarly, if I "upgrade" the syntax-rule to define-syntax, we run into
> the same problems. I thought that the following would work,
>
> (define-syntax (my-multiple-define stx)
>    (syntax-case stx ()
>      [(_ name1 name2 binding1 binding2)
>        #'(define name1 binding1)
>        #'(define name2 binding2)]))
>
> but it looks like this only returns the last syntax object, not both of
> them.
>
> (Note, my actual goal here is to define something, then define a syntax
> rule afterwards like
>
> (define-syntax (my-multiple-define stx)
>    (syntax-case stx ()
>      [(_ x y z)
>        #'(define x y)
>        #'(define-syntax-rule (z *stuff*)
>            *some random body to the syntax-rule*)]))
>
> , so the solution of using define-values to do all the defines in one step
> won't work for me.)
>
> I'd be satisfied either with knowing how to make a macro expand into
> multiple syntax objects (so that one macro can expand into both defines),
> or with someone letting me know how to define something, then define a
> syntax rule afterwards using only one syntax object (like wrapping them in
> a begin but that bumps the definitions inside to the outer scope).
>
> Many thanks in advance!
>
> --
> 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