From: Jim Weirich Date: 2003-03-25T20:47:26+09:00 Subject: Re: Iterate over two lists in parallel On Tue, 2003-03-25 at 02:22, Hal E. Fulton wrote: > I'd really rather use the object itself to > iterate, even if I must initialize it. > > Something like: > > x = [5,6,7,8,9] > x.reset > loop do > a = x.get > # ... > end > > C'est possible? It is possible to do it this way. In fact, Bertrand Meyer likes this style in that his Eiffel library defines his iterators as part of the collection object. I've never liked it though. Consider the following ... def outer_function stuff.reset while stuff.more? inner_function(stuff) end end def inner_function(list) list.reset # Oops ... we just blew away the iteration while list.more? # in the outer function do_somthing end end -- -- Jim Weirich jweirich@one.net http://w3.one.net/~jweirich --------------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)