On Mon, Oct 10, 2011 at 3:09 PM, Brendan Eich <bren...@mozilla.com> wrote:
> On Oct 10, 2011, at 1:41 PM, Bob Nystrom wrote: > > On Mon, Oct 10, 2011 at 1:33 PM, Dean Landolt <d...@deanlandolt.com>wrote: > >> >> Here's an example: >> >>> >>> let tree = [['a', 'b', 'c'], [['d', 'e'], 'f'], ['g']]; >>> >>> let inOrder = walk(tree); >>> for (node of walk(tree)) alert(node); // a, b, c, d, ... >>> >>> walk(tree) { >>> if (typeof tree == 'string') { >>> yield tree; // leaf >>> } else { >>> yield* walk(tree); // branch >>> } >>> } >>> >>> >>> What would the above look like without generators? >>> >> >> >> Woah there -- where does this syntax come from? Was `walk(tree) {...}` >> supposed to be `function* walk(tree) {...}` instead? Or is this intended to >> represent some sort of method generator? If the latter, doesn't this need >> some mechanism to distinguish it from a non-generator method? >> > > Whoops, my mistake. Too much time working on the class proposal where > "function" isn't needed for methods. > > > I spy a Dart ;-). > > > Yes, that should be function*. > > > Still a great delegated generator example. Thanks, > Bob sent me a more complete and much more convincing example off line. It was more convincing because he had three different algorithms use the same iterator. Did not convert me but I am at least moved out of the "no way" column. jjb > > /be > > > > _______________________________________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss