From: Eric Mahurin Date: 2005-09-30T22:57:20+09:00 Subject: Re: Class and Iterator Design Question --- Martin DeMello wrote: > Eric Mahurin 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