On Nov 28, 4:35 pm, MonkeeSage <MonkeeS... / gmail.com> wrote:
> On Nov 28, 3:22 pm, Charles Oliver Nutter <charles.nut... / sun.com>
> wrote:
>
>
>
> > MonkeeSage wrote:
> > > On Nov 28, 9:41 am, Charles Oliver Nutter <charles.nut... / sun.com>
> > > wrote:
> > >> MonkeeSage wrote:
> > >>> You actually need a generator, which can be implemented with
> > >>> continuations, but doesn't have to be (in 1.9 the generators are
> > >>> implemented with threads -- have a look at generator.rb in 1.8 and 1.9
> > >>> to see the differences). Using generators, you can implement izip (and
> > >>> all of itertools if you'd like, though most of it already has
> > >>> equivalent ruby solutions). Here is a pretty close translation of the
> > >>> python given in the itertools docs:
> > >> Ruby 1.9 also moves continuations out of core, but provides a form of
> > >> bounded continuations (coroutines) that's possible to implement in JRuby:
>
> > >> require 'fiber'
> > >> f = Fiber.new { a = 1; while true; Fiber.yield a; a += 1; end }
> > >> 5.times { puts f.resume }
>
> > >> $ jruby -J-Djruby.compat.version=ruby1_9 fiber_example.rb
> > >> 1
> > >> 2
> > >> 3
> > >> 4
> > >> 5
>
> > >> Under JRuby, it's using a native thread per live Fiber, so it's heavier
> > >> than in Ruby 1.9 which uses green threads. However they'll actually run
> > >> in parallel on JRuby, so that's a benefit. JRuby also supports a thread
> > >> pool in 1.1 that helps blunt the cost of spinning up native threads.
>
> > >> - Charlie
>
> > > 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

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