3 ms·
Intuitive hygienic macros (2009)
- jonathanyc 12y agoThis looks to me like essentially CHICKEN's implicit renaming macros[1][2]. It's interesting how good ideas evolve convergently. (For a bit of nitpicking, I'm aware the author generalizes on purpose, but I'm surprised that Lispers would actually find syntax-rules confusing (though the part about inflexibility I understand (although even so, unhygienic macros have been in Scheme implementations for a long time)) syntax-rules[3] is the clearest way to define macros I've ever seen (like implicit renaming macros without an option to 'inject', hence ir-macro-transformer).) [1]: http://wiki.call-cc.org/man/4/Macros#implicit-renaming-macros http://wiki.call-cc.org/man/4/Macros#implicit-renaming-macro... [2]: http://wiki.call-cc.org/explicit-renaming-macros#implicit-renaming-macros http://wiki.call-cc.org/explicit-renaming-macros#implicit-re... [3]: https://www.gnu.org/software/guile/manual/html_node/Syntax-Rules.html https://www.gnu.org/software/guile/manual/html_node/Syntax-R... Edit: I did some more research and it seems this article predated CHICKEN 4.7.0, which introduced ir-macro-transformer, by two years. That's pretty cool - I wonder if the article inspired CHICKEN, or if it was, like I supposed earlier, convergent evolution.
- lomnakkus 12y agoAre you familiar with Racket's define-syntax/syntax-parse? It's another step up in terms of power and actually allows for decent error handling!
- jonathanyc 12y agoThat looks pretty neat! Thanks, I'm reading up on it now.
- rntz 12y agoArticle author here. I don't actually remember why I found syntax-rules confusing, although I can make a couple of guesses: 1. Doing simple things with syntax-rules is simple, and that's most of what you use syntax-rules for, but it is actually possible to do very powerful things with it (Oleg Kiselyov has done terrifying things with it, for example). However, doing this is rather involved and complex. 2. Perhaps I preferred the conceptual simplicity of the lisp model that "a macro is just a function that returns an s-expression". syntax-rules is "yet another language" to learn (albeit a very simple one), while macros just reuse the lisp functions you already know. I hadn't seen Chicken's "implicit-renaming macros" until now, so thanks for the link!
- tempodox 12y agoI still prefer the down-and-dirty Lisp macros with explicit gensym. The problems that hygienic macros are supposed to solve don't even exist in Lisp (separate namespaces for functions & values, gensym when you need it). Sadly, the article doesn't even display a publishing date. A failure that afflicts surprisingly many tech blog articles. Makes it harder to gauge its merit.
- rntz 12y agoI published it on 2009-03-03. Dates are listed at http://www.rntz.net/index.html http://www.rntz.net/index.html but not in the articles themselves; I guess maybe I should fix that (not sure where a good place to put the date would be). I don't feel that separate function/value namespaces really solves the problem of hygiene. It just makes it less likely to come up in practice. It's an 80% solution: pragmatic but unsatisfying.
- tempodox 12y agoYou're right, separate namespaces don't actually “solve” the hygiene problem, but rather place responsibility squarely in your lap. It's the usual trade of more power for the price of more responsibility. What you call “unsatisfying”, I call “open for more interesting constructs, if you're up to it”. I wonder how many attempts might have been made to create a macro system that combines wanted capture with hygiene... As for article dates, I would expect a mature blogging platform to offer that choice without forcing you to insert the date manually, but then I'm not a blogger.
- rntz 12y agoThe article is about a macro system that gives you hygiene by default but allows you to capture when you want it. I'm not using a mature blogging platform.