A few things:

1. You're mixing elements of `syntax-rules` and `syntax-case` /
   `syntax-parse`. The former has an implicit template in its right-hand
   side, so you don't need the `#``, whereas you do with `syntax-case` /
   `syntax-parse`.

2. If you want this to define a function (as I'm guessing from the name
   `fun`), you should add parentheses around the name you're defining.

3. Because you're not trying to *match* the name `fun`, but only
   expanding to it, you don't need it in the literal list.

Here's a version that should do what you want:

    (define-syntax mysyn
      (syntax-rules ()
        [(mysyn element ...)
         (define (fun)
           (display element)
           ...)]))
    (mysyn 1 2 3)

Or, using the simpler `define-syntax-rule`:

     (define-syntax-rule (mysyn element ...)
       (define (fun)
         (display element)
         ...))


Of course, it's usually best to use functions wherever possible, and
only use macros as a last resort. Assuming you're planning to use the
code (i.e., you're not using it to learn about macros), I'd write it
like this:

    (define (fun . args) (for-each display args))

Functions compose more easily, and are easier to understand and to debug.

Vincent



On Wed, 30 Mar 2016 15:06:24 -0500,
cna...@cs.washington.edu wrote:
> 
> Consider a toy macro defined as:
> 
> (define-syntax mysyn
>     (syntax-rules(fun)
>       [(mysyn element ...)
>        (begin
>          #`(define fun
>              (display element)...))]))
> 
> and a list:
> (define l '(1 2 3))
> 
> Is there a way to call the macro like so: (mysyn l). When I try this, the 
> syntax object created looks like: '(define fun (display l)). 
> What I want it to look like is:
> 
> '(define fun 
>    (display 1)
>    (display 2)
>    (display 3))
> 
> 
> In other words, my question is whether/how I can pass the entire list to the 
> macro and let the macro be expanded on each element of it.
> 
> -- 
> 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.

-- 
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