[plt-scheme] Problem with syntax-case macro under MzScheme 352

From: Blake McBride (blake at mcbride.name)
Date: Sat Sep 9 10:06:14 EDT 2006

Greetings,

I am attempting to create a macro using define-syntax, syntax-case and
with-syntax under MzScheme 352.  I believe my macro definition is
correct but it just doesn't work under MzScheme.  The reason I believe
my macro definition is correct is because when I cause the macro to
quote it's output (to prevent evaluation) it returns the correct
expression.  When I try the expression outside the macro system it
works.

The following example and corresponding macro are simplified versions
of what I am actually doing but does demonstrate the problem.
Here is the example:

Input is:

(m4 gen)

Expected code to be executes is:

(begin
    (define  gen:g  '())
    (define  gen    '()))

So, I should end up with two variables being defined.  The macro
generates the correct code, but when it is run gen gets defined but
gen:g does not.  If I execute the above code manually, it works.  Why
doesn't it work through the macro?

The macro is:

(define-syntax m4
   (lambda (x)
     (syntax-case x ()
		 ((_ v)
		  (with-syntax ((name (string->symbol (string-append 
(symbol->string (syntax-object->datum (syntax v))) ":g"))))
			       (syntax (begin
					 (define name '())
					 (define v '()))))))))

Thanks.
Blake McBride




Posted on the users mailing list.