> On Fri, Mar 15, 2013 at 11:22 AM, Axel Rauschmayer <[email protected]> wrote: > I would prefer having to use `new` (but don’t have strong feelings about it): > generators are more like constructors than like functions. When I first > started experimenting with them in Firefox, it took me a while to figure that > out (even though it is obvious in hindsight). With `new`, I’d probably have > figured it out quicker. > > I agree with Tab: I wonder if your mental model for generators might not > continue to evolve. > > I would hate to have to write: > for (k of new tree.preorder()) > rather than: > for (k of tree.preorder())
Yes, it will probably evolve. The wish for `new` comes up if you know what’s inside a generator function and are surprised that you need to invoke a method to start executing the function body. If you treat it as a black box then `new` makes less sense, then it is roughly a function or method that returns an iterator. (Tongue in cheek, you could argue that Python does treat generators like classes) -- Dr. Axel Rauschmayer [email protected] home: rauschma.de twitter: twitter.com/rauschma blog: 2ality.com
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

