Ka-Ping Yee wrote: > > On Mon, 5 Feb 2001, M.-A. Lemburg wrote: > > Two things: > > > > 1. the proposed syntax key:value does away with the > > easy to parse Python block statement syntax > > Oh, come on. Slices and dictionary literals use colons too, > and there's nothing wrong with that. Blocks are introduced > by a colon at the *end* of a line. Slices and dictionary enclose the two parts in brackets -- this places the colon into a visible context. for ... in ... : does not provide much of a context. > > 2. why can't we use the old 'for x,y,z in something:' syntax > > and instead add iterators to the objects in question ? > > > > for key, value in object.iterator(): > > ... > > Because there's no good answer for "what does iterator() return?" > in this design. (Trust me; i did think this through carefully.) > Try it. How would you implement the iterator() method? The .iterator() method would have to return an object which provides an iterator API (at C level to get the best performance). For dictionaries, this object could carry the needed state (current position in the dictionary table) and use the PyDict_Next() for the internals. Matrices would have to carry along more state (one integer per dimension) and could access the internal matrix representation directly using C functions. This would give us: speed, flexibility and extensibility which the syntax hacks cannot provide; e.g. how would you specify to iterate backwards over a sequence using that notation or diagonal for a matrix ? > The PEP *is* suggesting that we add iterators to the objects -- > just not that we explicitly call them. In the 'for' loop you've > written, iterator() returns a sequence, not an iterator. No, it should return a forward iterator. -- Marc-Andre Lemburg ______________________________________________________________________ Company: http://www.egenix.com/ Consulting: http://www.lemburg.com/ Python Pages: http://www.lemburg.com/python/
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4