3 ms·
i see no macros, why not add the feature that lets users add features?
by eschulte 15y ago
i see no macros, why not add the feature that lets users add features?
- indy 15y agoWouldn't it be harder to use macros effectively in a non-homoiconic language?
- jmesserly 15y agoThat's a fair point. Would the AST strawman proposal (http://wiki.ecmascript.org/doku.php?id=strawman:ast http://wiki.ecmascript.org/doku.php?id=strawman:ast) get you most of the way there? If nothing else, it would make some metaprogramming of the source tree possible. Combine that with module loaders (http://wiki.ecmascript.org/doku.php?id=harmony:module_loaders http://wiki.ecmascript.org/doku.php?id=harmony:module_loader...) and I think you're pretty close to macros.
- munificent 15y agoI'm on the Traceur team, but I don't speak for all of us (or Google). Personally, I think macros would be really cool, but they're a challenge in a language that isn't homoiconic, has both statements and expressions, and a pretty complex grammar. I don't know if it would be possible to design a general purpose macro system within those limitations that was usable by mere mortals. I see macros as being useful for two things: 1) DSL-type "make my own inner language" stuff, and 2) conditional evaluation. JS is already pretty syntactically flexible, especially with object literals, so that covers some of (1). JS already has closures, so if we can get a nicer function literal syntax, that makes it tolerable to do (2) just by passing functions around (and it's more explicit, which is good to some people).
- olov 15y agoI'd also like to see macro capabilities in JS, although as others have said it's not trivial (but certainly not impossible) to add. For what its worth JSShaper [http://jsshaper.org http://jsshaper.org] may be of interest although it doesn't provide macros per se. It's an extensible framework for JavaScript syntax tree shaping (rewriting/transforming). For a macro-like example, I described how I created an assert plugin for it here: http://blog.lassus.se/2011/03/c-style-assertions-in-javascript-via.html http://blog.lassus.se/2011/03/c-style-assertions-in-javascri... It gives you the power of macros and some, but with more power comes more complexity. Declarative style matching and rewriting remediates some of that, and it's the direction I'm taking JSShaper in.