[plt-scheme] Macro problems: function application is not allowed

From: Noel Welsh (noelwelsh at yahoo.com)
Date: Tue Feb 3 16:36:21 EST 2004

I thought I had macro-fu...

I'm trying to define a macro that contains mutally
recursive macros and functions.  It has the form:

    ((name param ...) pattern))

Where pattern is 
  | (a rest ...)
  | a rest ...

It should expand into a form that matches (name param
...) against a tree and returns pattern when matches
are found


    ((move a) (move (/ a 2))))


  (match-define loop
    [(list) (list)]
    [(list head tail ...)
      (match head
	     [(struct word (a b))
              (cons (make-word (/ a 2)) (list))])
      (loop tail))])

Not very complicated, except...

I'm using a macro to compile the pattern into code,
I can't get it play nicely.  I get the error message:

compile: bad syntax; function application is not
allowed, because no #%app syntax transformer is bound
in: (lambda (stx) (syntax-case stx () ((_) (list)) ((_
head rest ...) (cons head (production rest ...))) ((_
(head subtree ...) rest ...) (cons (production head
subtree ...) (production rest ...)))))

???  I attach the macro below.  Any help greatly



(define-syntax (l-system stx)
    (syntax-case stx ()
        ((name param ...) rhs ...) ...)
             (lambda (stx)
               (syntax-case stx ()
                 ((_ head rest ...)
                  (cons head (production rest ...)))
                 ((_ (head subtree ...) rest ...)
                   (production head subtree ...)
                   (production rest ...)))))))
                 [(list) (list)]
                 [(list (list head subtree ...) rest
                  (append (matcher head subtree)
                          (loop rest))]
                 [(list head rest ...)
                  (matcher head rest)])]
               (lambda (head rest)
                  (match head
                    [(struct name (param ...))
                     (production rhs ...)]

Email: noelwelsh <at> yahoo <dot> com
Jabber: noelw <at> jabber <dot> org

Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!

Posted on the users mailing list.