Ruby needs continuations

MonkeeSage wrote:

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?

http://jira.codehaus.org/browse/JRUBY

  • Charlie

On Nov 28, 3:22 pm, Charles Oliver N. [email protected]
wrote:

python given in the itertools docs:
3
I just tried the above izip function in jruby, but it only gave me two
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?

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.

Regards,
Jordan

MonkeeSage wrote:

Bug #1635 [ http://jira.codehaus.org/browse/JRUBY-1635 ]

Cool, thanks. Now if you’re really ambitious, maybe you can fix it :slight_smile:

  • Charlie

On Nov 28, 4:35 pm, MonkeeSage [email protected] wrote:

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.

Regards,
Jordan

Bug #1635 [ http://jira.codehaus.org/browse/JRUBY-1635 ]

On Nov 29, 1:05 am, Charles Oliver N. [email protected]
wrote:

MonkeeSage wrote:

Bug #1635 [http://jira.codehaus.org/browse/JRUBY-1635]

Cool, thanks. Now if you’re really ambitious, maybe you can fix it :slight_smile:

  • Charlie

Looks like somebody already beat me to it (with bells on!) [
http://jira.codehaus.org/browse/JRUBY-1635 ]; not that I’d have been
any help anyway.

Regards,
Jordan

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.

Regards,
Jordan