[plt-scheme] Problem with syntax-case macro under MzScheme 352
On Sep 9, Blake McBride wrote:
>
> I probably mean something like procedural macros that allow you to
> specify exactly what you want without trying to do it in some higher
> level 4th generational descriptive pattern language. I believe
> there is an SRFI about this.
Well then, `define-syntax' does just that. When you write:
(define-syntax foo
(lambda (stx)
...))
you bind `foo' -- as a syntax -- to a syntax->syntax transformer
procedure. How you implement the procedure is up to you --
`syntax-rules' can construct simple transformers very easily, and
`syntax-case' gives you only the pattern matching part in an easy
way. But nothing prevents you to write your own body in the above
definition, and you can use the basic syntax manipulation tools
(syntax-e, syntax-object->datum and datum->syntax-object).
So the only differences between this and CL's `defmacro' is:
* MzScheme passes the whole form as a single argument,
* The values are more than just s-expressions.
"procedural" applies to both systems.
> A procedural macro language is easier to understand in all but the
> simplest cases.
Wrong, since they are all procedural.
> It is possible to have a procedural macro extension that is
> hygienic.
Right, which is just what these things are. (You can also view the
expansion of `syntax-rules' and see that there's no magic involved.)
> Descriptive languages are great for simple cases and absolutely
> unwieldy or impossible for complex cases.
Ugh, I'll avoid a comment, since "descriptive language" is not a well
defined concept here.
> I know you understand syntax-case and friends but the ongoing volume
> of questions about scheme macros on the net is indicative of a
> problem. Average programmers should be able to use a languages
> without becoming a language expert. And, I don't believe that the
> complexity is necessary.
My conclusion is that dealing with bindings is hard no matter how you
look at them. In MzScheme you need to deal with the above, and in CL
you need to be aware of places that should be `gensym'ed (plus CL's
restriction of not overriding any builtins). In short, I believe that
the complexity *is* necessary. (And therefore I'm not surprised that
there are many solutions.)
> (Sorry. I'm not directing any of this at you. This is a product of
> my ongoing frustration over scheme's macro system. I spend a bunch
> of effort, basically figure it out, don't use it for a while, and
> I'm back to ground zero. I almost never use lisp macros but they
> are always clear to me.)
You can always use the defmacro library and do the same things you did
in CL. They'll break in similar ways too though.
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!