4 ms·
First let me say that as a long time Schemer, and one who did his graduate work on the semantics of macros, I am quite positively disposed towards macros. In th
by dherman 16y ago
First let me say that as a long time Schemer, and one who did his graduate work on the semantics of macros, I am quite positively disposed towards macros. In theory, I think it'd be great for JavaScript to develop a macro system.
That said, macros are much harder to design, and much less well understood, than modules. Worse, macros in the context of a dynamically loaded global scope (e.g., JavaScript's global object) are a complete mess. The Scheme community is actually quite divided over this issue. Some portions of the Scheme community favor a much more dynamic semantics for macros, more in the Lisp tradition; others favor building macros on top of a more compilation-friendly semantics -- often, not coincidentally, built on top of a static module system. As an example, I'd recommend looking into the Racket programming language (formerly known as PLT Scheme), which has a built-in module system fairly similar to the one we've designed for Harmony -- and which leverages this module system to support one of the most powerful macro systems in the history of programming languages.
Next, one of the central aims of the module system design is to correct some of the past mistakes in JavaScript's scoping semantics. These are things that can't just be desugared away by simple macros. They require actual changes to the way whole JS programs are compiled and executed.
Finally, I'll add that it's easy to write a few code snippets on your blog and pretend it's a design, but it's nowhere near what is required to see a design all the way through. It's not even enough for the introductory text of a proposal. But if you have serious proposals to make, I'd encourage you to join es-discuss and make positive, substantive contributions to the conversation. However, I should warn you that well-designed macro systems are still very much the stuff of research.
- alnayyir 16y agoFacile snarky one-offs are sugary and lacking in intellectual nutrition, thus, popular. Persistence, hard work, testing, all the sweat required to make something meaningful? Gross.
- WalterGR 16y agoSome portions of the Scheme community favor a much more dynamic semantics for macros, more in the Lisp tradition; others favor building macros on top of a more compilation-friendly semantics Forgive my ignorance, but aren't Lisp's semantics very compilation-friendly? Doesn't macro expansion happen at read-time? EDIT: I think that's the case for Common Lisp. By "the Lisp tradition" did you mean prior dialects?
- ToastOpt 16y agoyou still can have dynamic semantics at read-time -- eg, does the macro-expand in reading the first form load new macros that affect the next form? Eg, in (progn (M) (M)), is it ever the case that the second M will dispatch to a different macro definition than the first M? In the world of Common Lisp, yes. In the world of R6RS's more static semantics, no.