From: Pit Capitain Date: 2002-11-20T04:11:24+09:00 Subject: Re: ruby-dev summary 18711-18810 On 20 Nov 2002 at 2:59, Bob Alexander wrote: > From: "Pit Capitain" > > > Do you know implementations like (from Ruby CVS) > > rough/lib/generator.rb? Why do you think these are inefficient? > > I haven't seen that (but I'll definitely take a look). I think > generators can be implemented efficiently. In my experience with > generators in other languages, the time efficiency is good enough, and > depending on the underlying language implementation, they can be > costly of space since in some implementations they require their own > contiguous stacks (almost like threads -- to support suspended C > stacks in the underlying C code). Hi Bob, thanks for the clarification. I wasn't sure what you meant by "inefficient". The (generic) iterator implementations presented so far seem to be at least space-inefficient, because they either create arrays or use threads/continuations. > If Ruby has an efficient generator capability, it would be a good way > to implement "zip" without the space cost of creating an entire copy > of all of the pointers in all involved sequences. Not yet, but Matz seems to be working on it. > BTW, I have quite a bit of experience with languages that support > generators (...) > I attached a small experimental Ruby class I > wrote a long time ago that implements something like this. The > implementation uses threads and queues, so is not very efficient. But the code is a nice read, thanks a lot. > However, an API of this sort could possibly be implemented efficiently > at a lower level. If I understood Matz correctly he's working on a low-level implementation of zip, but doesn't like external iterators (sigh). Regards, Pit