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

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

Never mind, I figured it out.  The macro should have been:

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

I figured it out by using Chez Scheme.  It gave me a meaningful message
with the wrong macro.  MzScheme lets it run and hints that it's right.

I can't hardly imagine making it any more complicated.  The simplest
things are made rocket science with define-syntax and friends.  Lisp
macros may not be perfect but normal people (those who don't devote
their life to understanding the intricacies of syntax-case) can use
and understand it.  Syntax-case is killing scheme.

Blake McBride



At 09:06 AM 9/9/2006, Blake McBride wrote:

>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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20060909/aa14999c/attachment.html>

Posted on the users mailing list.