Salvador de la Puente González (2014-08-25T09:17:20.000Z)
domenic at domenicdenicola.com (2014-09-08T23:20:09.771Z)
On 20 Aug 2014 17:39, "Tab Atkins Jr." <jackalmage at gmail.com> wrote: > Generators produce iterables, and you can just use a tee() function to > "clone" an iterable. It's not hard to define yourself, and Python has > a reference implementation: > https://docs.python.org/2/library/itertools.html#itertools.tee tee() function has two main problems. First and most important, it does not allow you to communicate different information by using send() on the new generators. The new generators, though independent, are actually tied to the state of the original iterator which leads to the second problem: the waste of space. You need to keep repeated values for each of the cloned generators. My proposal performs only a shallow copy of the current state and most important, the execution state which allow you to send different information for the next iteration step. They are real independent generators. > You can currently pass values back into the generator by passing an > argument to .next(), and the generator can use that to do whatever it > wishes, such as changing its internal state or jumping to a label. AFAIK, jumping to a label is not possible in ES5. You can only skip a labelled sentence. Indeed you can use the next information for changing the state. It's how I'm doing it right now but transpiling the functions this way is quite obscure. I don't know if there are goto discussions in this list but it is one of my concerns, if JS is becoming something like the "high level target language of the web", to provide a powerful enough flow control sentence like goto. I know the dangers behind this sentence and this is because I propose to limit its usage inside generators where scope is controlled and limited. You can not jump between functions and the jumping is controlled externally. The proposed goto() method does not send or advances the generator, it only changes the execution point. It can be completed with gen#yields() which would return all labels for labelled yields.