Check out Dart's iterators

David Bruant bruant.d at
Sun Feb 10 12:13:52 PST 2013

I have continued my wanderings on that topic elsewhere. Sharing as food 
for thought:

Le 10/02/2013 16:21, David Bruant a écrit :
> <idealworld>
I initially thought that yield could be the sugar of "endframe as 
yield(value)", but yield and return/throw are different. In the former 
case, the frame can (and likely will) be re-entered which is not the 
case for the latter. This begs for 2 different keywords. Let's call them 
"endframe" and "yield". yield could come in 2 forms:
     // generic
     yield as return(value)
     yield as throw(value) // which is impossible today?

     // sugar
     yield value
     // which desugars naturally to
     yield as return(value)

To re-enter a frame, the following could be used:
     reenter generator as return("yo") // equivalent of current 
     reenter generator as throw("yo") // equivalent of current 

This raises an error if "generator" is not re-entrable (that is if it 
didn't end with yield or one of its sugar).

What is lost is the ability to pass around the send/throw/close/next 
functions. I would consider this a win. From what I've seen of 
generators, there is no loss. At least, task.js doesn't seem to pass 
these functions around.

Since every generator additional methods would be reimplemented with 
syntax, I think that having yield/reenter keywords (and additional sugar 
for usability), generators wouldn't need to be their own new function type.
But that's in an ideal world, of course.
> </idealworld>


More information about the es-discuss mailing list