Questions/issues regarding generators

Jason Orendorff jason.orendorff at gmail.com
Mon Mar 11 23:29:02 PDT 2013


On Mon, Mar 11, 2013 at 8:57 AM, Dmitry Lomov <dslomov at google.com> wrote:

> This semantics is sound and consistent, but there is a problem: by that
> logic, the first call 'zip(rangeAsArray, rangeAsArray)' also has all
> the appearances of a user error! It requires careful analysis and thinking
> to convince oneself that it is indeed correct. Well, maybe not in a simple
> case when the initializer of rangeAsArray is an array literal, but as soon
> as the initializer is more complicated - say an external function, you can
> never be sure.
>

But you could argue the same way for literally any other operation on an
object. 'rangeAsArray.length', for example, would also be nonsensical if
rangeAsArray turns out to be some other sort of object and not an array
after all.

If we are to presume that this particular kind of bug will be common in JS,
why isn't it common in Python?

Note that generators return coroutine objects with methods other than just
the iteration-related methods. The coroutine state, to my mind, is inherent
to the returned object.

-j
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130312/88104f96/attachment.html>


More information about the es-discuss mailing list