[Prothon-user] Terminology: generator/iterator/iterable
Greg Ewing <[email protected]> Fri, 02 Apr 2004 12:34:32 +1200
| Newsgroups | gmane.comp.lang.prothon.devel |
|---|---|
| Message-ID | <[email protected]> |
Mark Hahn <[email protected]>: > I have an idea for making everything that normally returns a list in Python > return a generator in Prothon A point here about terminology: if you're trying to keep Prothon terminology in sync with Python terminology, you should be aware that there's a difference between an "iterator" and a "generator" in Python, and I think you really mean "iterator" here. In Python terms, an iterator is an object which responds to the iteration protocol -- it has a next() method which returns the next item or raises StopIteration. A generator is a special kind of function that produces iterators. Note that the generator itself is *not* and iterator -- it *returns* an iterator when you call it. Also note that generators are not the only things which produce iterators -- they just happen to be one way of doing it. Built-in methods such as dict.iteritems return iterators, but they don't involve generators in any way. The other term related to all this is "iterable", which is an object having an __iter__ method that returns an iterator. It's important to also not get "iterable" and "iterator" confused. Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | [email protected] +--------------------------------------+