Ruby 1.9 also moves continuations out of core, but provides a form of
4
iterations…
Could be a bug in generator; could you try it on a more recent release
(like 1.0.2 or 1.1b1) and report it if it’s actually a problem?
continuations, but doesn’t have to be (in 1.9 the generators are
5.times { puts f.resume }
in parallel on JRuby, so that’s a benefit. JRuby also supports a thread http://jira.codehaus.org/browse/JRUBY
Charlie
I downloaded the precompiled versions of 1.0.2 and 1.1b1 and both
displayed the same behavior. I’ll submit a bug report.
On Nov 28, 10:53 am, “Just Another Victim of the Ambient M.” [email protected] wrote:
yield result
}
Thank you, MonkeeSage, this is exactly what I'm looking for!
It's interesting thatgeneratorsare slow enough to warn users about its
lack of speed! Do you know if it would be any faster implemented with
continuations? I’m surprised it’s so slow considering Ruby employs green
threads…
Just for posterity, it should be noted that in this particular example
(and several others from itertools), you don’t even need generators;
internal iterators work just fine…
def izip(*enums)
(enums[0].length).times { | i |
elems = enums.map { | enum |
enum[i]
}
yield elems
}
end
izip([1,2,3], [4,5,6], [7,8,9]) { | elem |
p elem
}
Of course, you have to be wary about gotchas regarding the elements
being iterable and so forth; just thought it was worthy of mention
that this is possible with the built-in iteration construct, without
resorting to external iterators.