From: Eric Mahurin Date: 2005-09-30T06:17:10+09:00 Subject: Re: Class and Iterator Design Question --- gabriele renzi wrote: > Eric Mahurin ha scritto: > > >>>I believe that's the plan. I think all the standard > >> > >>iterators are > >> > >>>going to start returning enumerator objects when called > >> > >>without a block. > >> > >>>James Edward Gray II > >> > >>would'nt it make more sense to have yield work coroutinish > >>when called > >>withouth a block, basically integrating the enumerator > >>functionality in it? > > > > > > That sounds unnecesarily complex. If it is what I think > you > > are talking about, you'd return some kind of object with a > > continuation when you hit a yield without a block (like a > > generator?). An example would help explain what you are > > talking about. > > > > I think the current plan with Enumerators sounds better. > > My apologize, I actually meant "Generator" not "Enumerator". > > Anyway, yes, just like a Generator, and for all the usage of > yield, not > just for Enumerables. > This, in my opinion, would be more consistent and preserve > the semantic > of yielding better than returning an Enumerator, but it seem > this > decision was already taken in the direction you like, judging > from a > recent patch. a) hardly anybody finds use in generators b) generators are slow because of continuations c) if the method yielding returns something useful (almost all methods in Enumerable except each/each_with_index), nothing would receive this value because the method would return a generator instead. I think this is only useful for each-like methods. If you want external iterators, I don't think Generator is the way to go. If you want an external iterator, you should build it into the class (i.e. IO has one) or have another class hold an index into the collection (look at my cursor package or Simon Strandgaard's iterator). I may put a generator (probably Cursor::Enumerable) in my cursor package at some point, but I don't expect much usage because of the performance. ______________________________________________________ Yahoo! for Good Donate to the Hurricane Katrina relief effort. http://store.yahoo.com/redcross-donate3/