[plt-scheme] On hygiene and trust
2009/7/9 Joe Marshall <jmarshall at alum.mit.edu>:
>> http://blog.plt-scheme.org/2009/05/explicit-renaming-macros-implicitly.html
>
> This entry makes my point exactly. syntax-case is just too low-level.
> Sure, defmacro is even *lower* level, but that makes it easier to understand.
>
> Suppose I want a macro that examines one of its arguments to see if it
> is a lambda expression. The ideal thing, of course, is a function that
> does just that:
>
> (define-syntax foo
> (lambda (stx)
> (if (lambda-expression? (first-argument stx))
> ....)))
>
> At least defmacro allows this:
> (defmacro foo (arg0 &rest args)
> (if (eq? (car arg0) 'lambda) ;; crude, but effective
I can't speak too much about the hygiene part of the issue, but as far
as the "practical syntax for deconstructing things" goes, in CL, with
fare-matcher, I do things like
(match expr
(`(lambda ,formals , at body) ...)
...)
As long as you're deconstructing things this way, you don't have to
care about the underlying representation. One catch though -- in a
syntaxful macro-system, you soon realize that there are more
non-terminals than the "sexp", and then you need one "backquote"
operator per non-terminal, and/or your backquote form should
optionally take an argument specifying the non-terminal, an argument
specifying the syntactic context (at which point we're doing explicit
renaming), and maybe another to specify a tag with which to match
unquotes (as in Slate).
More generally, I *hate* that syntax-rules provides a pattern matcher
that is wholly unrelated to anything else in the base language. If
pattern matching is good at the meta-level, then the base-language
should have it too, and the macro layer should be using the very same
pattern-matching mechanism. Otherwise, your language design is no
better than C++ with its pure-functional meta-language for templates
that is wholly unrelated to its base language.
[ François-René ÐVB Rideau | Reflection&Cybernethics | http://fare.tunes.org ]
I'd rather write programs that write programs than write programs -- Dick Sites