5 ms·
Great idea. Generators are one of the features that still seperate coffeescript from python, in terms of productivity/elegance. Still missing is a syntax to co
by bayesianhorse 13y ago
Great idea. Generators are one of the features that still seperate coffeescript from python, in terms of productivity/elegance.
Still missing is a syntax to consume these generators, like in "for a in b" or "yield from"
- almost 13y agoDefinitely agree with need for iteration syntax and yieldfrom keyword. The iteration syntax will probably have be something different than "for a in b" because that's already used for array-like iteration and adding another case would slow existing code down (all of which wouldn't be using it of course). For yieldfrom the code it needs to generate is something like this: var generator = g1(), result = {}, send; while(!result.done) { result = generator.send(send); send = yield result.value; }
- bayesianhorse 13y agoI would suggest "for a from b". If that only uses .next and .send, it might work with class instances too, like the iterator protocol in Python.
- apaprocki 13y ago"for of" is actively being added to V8. It should not be very long before it lands in V8 (and thus in Node). I don't like the idea of another keyword that at best acts exactly the same (or at worst acts subtly different).
- almost 13y agoCoffeeScript already has an of operator (like js in) and an in operator (array like iteration) neither of which could easily be made to both (I think). So we'd probably need a new name. Once "of" is in V8 we can compile to it directly though.
- wycats 13y agoIt's not clear to me how to compile directly to it without breaking CoffeeScript code that already uses for/of. Is the idea to break compatibility with existing CoffeeScript code? See my longer question about this upthread.
- almost 13y agoI honestly don't know, this was just a quick hack this morning while I had a hangover :) I think it's good to have the conversation though!
- bayesianhorse 13y agoI'm not current on what kind of compatibility coffeescript is trying to keep, but IE6 certainly not going to like the newer V8 features...
- csense 13y agoFrom the article: > Update: I've created a PR [pull request] for CoffeeScript. I've also just added the yieldfrom keyword... Maybe this update happened after your comment?
- almost 13y agoYes, both updates happened after that comment. In fact that comment provided a little extra motivation for me to get those extra features done :)