> Should people prefer to write: > > for item from iterator: > do something > > when they only need to loop over something once? This shows up a problem with Ping's proposal, I think: The place where you write the for-loop isn't the place where you know whether something will be iterated over more than once or not. How is a library routine going to know whether a sequence passed to it is going to be used again later? It's impossible -- global knowledge of the whole program is needed. This appears to leave the library writer with two choices: (1) Use for-in, to be on the safe side, in case the user doesn't want the sequence destroyed -- but then it can't be used on a destructive iterator, even if the caller knows he won't be using it again; (2) use for-from, and force everyone who calls it to adapt sequences to iterators before calling. Either way, things get messy and complicated and possibly dangerous. Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg@cosc.canterbury.ac.nz +--------------------------------------+
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