From: Austin Ziegler Date: 2007-11-28T22:00:47+09:00 Subject: Re: Ruby needs continuations... On 11/28/07, Vitor Peres wrote: > On Nov 28, 2007 10:30 AM, Just Another Victim of the Ambient Morality < > ihatespam@hotmail.com> wrote: > > How would one do this in Ruby? You can use .each_with_index and index > > the other list but that assumes that the other list is indexable, which > > only happens to be true of arrays but is not true in general. I've thought > > about implementing some Ruby equivalent of zip() (or preferably izip()) and > > discovered that I can't do so without continuations. Actually, Ruby 1.9 is losing continuations (hard to do with native threads, expensive for stack frame manipulation in JRuby). However, you don't need continuations to do parallel iteration, as Vitor suggests: > Ruby does, however, have an implementation of zip in Enumerable. You can do > > list1 = [1, 2, 3, 4] > list2 = ['a', 'b', 'c', 'd'] > > list1.zip(list2).each {|num, letter| puts "#{num} #{letter}" } > > just fine. You'll actually get the same result you would with your Python > example. You're also able to do: a.zip(b, c, d, ...) to iterate multiple lists in parallel. -austin -- Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/ * austin@halostatue.ca * http://www.halostatue.ca/feed/ * austin@zieglers.ca