[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: Class and Iterator Design Question
From:       Eric Mahurin <eric_mahurin () yahoo ! com>
Date:       2005-09-30 13:57:20
Message-ID: 20050930135652.70742.qmail () web36113 ! mail ! mud ! yahoo ! com
[Download RAW message or body]

--- Martin DeMello <martindemello@yahoo.com> wrote:

> Eric Mahurin <eric_mahurin@yahoo.com> wrote:
> > 
> > a) hardly anybody finds use in generators
> > 
> > b) generators are slow because of continuations
> 
> I think this is a case of "b causes a" - python, for
> instance, uses
> generators and people find plenty of uses for them.

I think the main cause of (a) is the presence of internal
iterators in Ruby.  Ruby uses internal iterators as a standard
and Python uses external iterators (including generators) as a
standard.  I think Python users may go for generators because
they don't have easy to use internal iterators.  Maybe Python
makes an optimization to context switching (continuations) for
generators.  It probably reuses the same alternate stack space
for each yield whereas ruby's generators create a new
continuation object for each yield.

I just don't see the practical use of generators in ruby
(relative internal iterators).  When you end up REALLY needing
something like generator where you pull elements rather than
them being pushed to you (like in an internal iterator), I
think the majority of those cases need a more robust external
iterator interface.  Even optimally implemented, a generator
can only efficiently (O(1)) provide getting the next element. 
A more general external iterator may also be able to do these:
go in either direction, write, insert, delete, save/restore
position, etc.



		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic