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

  (l-system 
    ((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

So

  (l-system
    ((move a) (move (/ a 2))))

=>

  (match-define loop
    [(list) (list)]
    [(list head tail ...)
     (append
      (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,
and
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
appreciated!

Noel

----------------------------------------

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


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

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/


Posted on the users mailing list.