Steven D'Aprano wrote:
On Sat, 20 Jun 2009 01:55:42 pm John Graham wrote:
Hrm, that leads to the question, is it mathematically possible to iterate over an infinite list... twice? :)
Mathematically, yes. Practically, no.
Mathematically, the trick is to ensure that the time it takes to iterate over each item approaches zero sufficiently fast. E.g. if it takes 1 unit of time to process the first item, and 1/2 units of time for the second, and 1/4 for the third, 1/8 for the fourth, etc, then you can iterate over an infinite number of items in 2 units of time total. Then you can do them all again :)
It is also possible to do parallel iteration, but I'm not sure that mathematically parallel processing makes sense. I'm not even sure that mathematically there is such thing as iteration (that does not involve recursion).