Friday, April 22, 2005

Ask and ye shall receive my bugs

Naturally, the macro I posted yesterday is broken. (It was only a matter of time, right?) Sadly, not only did I have to rely on Ryan to fix it for me, but I don't even quite understand the fix. In fact, he doesn't even totally understand why the fix worked. Bleah.

Let's consider a hypothetical example to understand the problem better. The user invents a new language called my-lang with keywords foo and mumble, and a variant of syntax-case called my-syntax-case. The problem has to do with the fact that the definition of the my-syntax-case macro introduces foo and mumble into its output (because invocations of my-syntax-case don't have to mention the keywords). So they get fresh marks, which distinguish them from the original foo and mumble. The solution is to cancel the fresh marks with syntax-local-introduce.

I won't reproduce the entire corrected macro, but here's the relevant portion of the second of the two cases (the simpler one, where there is no parent language):
;; define the new language-specific syntax-case variant
(define-syntax (case stx)
(syntax-case stx ()
[(_ stx-exp (extra-kw (... ...)) clause (... ...))
(with-syntax ([(k (... ...))
(map syntax-local-introduce
(syntax->list #'(kw ...)))])
(syntax-case stx-exp (k (... ...) extra-kw (... ...))
clause (... ...)))]))
Also, I should point out that it wasn't necessary to require at least one clause in the syntax-case variant, so I've corrected that, too.

No comments: