From: "Hal E. Fulton" Date: 2003-03-25T16:22:29+09:00 Subject: Re: Iterate over two lists in parallel ----- Original Message ----- From: "Jim Weirich" To: "ruby-talk ML" Sent: Tuesday, March 25, 2003 12:57 AM Subject: Re: Iterate over two lists in parallel > I don't know what you have in Gen, but I would expect it to work > something like this ... > > x = [5,6,7,8,9] > it = x.iterator > loop do > a = it.get > break if a.nil? > p a > end > > A generator is really just a fancy external iterator. So you need an > operation to create it (hence the iterator call). You then use the > iterator to, ummm, iterator; not the array itself. > > The iterator method will probably look something like this .... > > def iterator > Generator.new { |g| each { |it| g.generate(it) } } > end > > That's the only thing you would need to mixin. Generator can still > stand alone. > > Does that help? Yes... I was mistaken in that I was initializing the generator all right, but then was calling a method of Array... and wondering why I got Continuations out. :D 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? Hal