April 10 2014 Meeting Notes

Jason Orendorff jason.orendorff at gmail.com
Thu Apr 24 13:24:59 PDT 2014

On Thu, Apr 24, 2014 at 2:16 PM, Brendan Eich <brendan at mozilla.org> wrote:
> The only proposal (let's table whether the name is 'return' or @@return) is
> whether for-of constructs should have a finally maybe-call of the iterator's
> return method, if present. Like SpiderMonkey's JS1.7-1.8 close method, based
> in part on Python 2.5 and up.

But in Python, closing iterators is part of the protocol. It isn't
mentioned in the language specification (Python does not have a
detailed spec) but all language and library facilities that consume
iterables do it, not just for loops.

For example, given this generator:

    def f():
            yield 0

note the lines that say "closing" in both examples below:

    >>> [FAIL for i in f()]
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'FAIL' is not defined

    >>> map(lambda: FAIL, f())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: <lambda>() takes no arguments (1 given)

Even things like zip(), which can't be written in terms of a for loop,
close iterators on error.


More information about the es-discuss mailing list