[plt-scheme] Problem with syntax-case macro under MzScheme 352
On Sat, 2006-09-09 at 09:34 -0500, Blake McBride wrote:
>
> 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 '()))))))))
How about the following:
(define-syntax (m4 stx)
(define (symbol-append . args)
(string->symbol (apply string-append (map symbol->string args))))
(define (add-suffix stx suf)
(datum->syntax-object stx (symbol-append (syntax-e stx) suf))))
(syntax-case stx ()
[(_ v) (with-syntax ([name (add-suffix #'v ':g)])
#'(begin (define name '())
(define v '())))]))
That seems simple enough, especially since `symbol-append' really ought
to be in a standard macro-writing library.
And if you're having trouble debugging your macros, I recommend Ryan
Culpepper's excellent macro debugger, which is available in the nightly
releases.
sam th