[plt-scheme] Struggling with macro...

From: Paulo J. Matos (pocm at soton.ac.uk)
Date: Wed May 23 08:03:03 EDT 2007

Hi all,

Even though from time to time I can write a macro, unfortunately I
feel they are not yet clear enough for me.

I'm doing a macro to recognise the following:
(machine <name>
       (variables (<varname> <value>)
                         (<varname> <value>)
                         (<varname> <value>)
                         etc.)
      ... (other syntax))

I've done some simple structure to keep the information of machine
macro called mc and function to save information to structure.
So, macro is something like this:
(require-for-syntax "mc-utils.scm")

  (define-syntax (machine stx)
    (syntax-case stx ()
      [(_ mname sexps ...)
       (identifier? #'mname) ; fender
       #'(let ([mc (make-mc () () () () ())])
           #,(with-syntax ([variables (syntax-case #'(sexps ...) (variables)
                                        ((variables (name value) ...)
                                         (andmap identifier? #'(name ...))
                                         ((add-variable-to-mc #'name
#'value) ...)))])
               #'variables
               #'mc))]))

This gives me: syntax: no pattern variables before ellipses in template in: ...
in the second ellipsis of with-syntax.
I want to expand:
(machine hello
       (variables (x 1)
                         (y 2)
                         (z 3)))

to
(let ([mc (make-mc () () () () ())])
     (add-variable-to-mc x 1)
     (add-variable-to-mc y 2)
     (add-variable-to-mc z 3)
     mc)

It seems that no matter what I change I get some kind of wierd error.
Can you please point me out in the right direction? (sorry for
presenting such ugly and probably full or error macro).

Cheers,
-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK


Posted on the users mailing list.