Re: Class and Iterator Design Question



--- gabriele renzi <surrender_it@xxxxxxxxxxxxxxxx> 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/



.



Relevant Pages

  • Re: How to identify generator/iterator objects?
    ... generator/iterator that can yield iterators, generators, and other data ... generator and iterator objects. ... So while I can identify iterators, I can't identify generators by class. ... But f is not a generator, ...
    (comp.lang.python)
  • How to identify generator/iterator objects?
    ... I'm trying to write a 'flatten' generator which, when give a generator/iterator that can yield iterators, generators, and other data types, will 'flatten' everything so that it in turns yields stuff by simply yielding the instances of other types, and recursively yields the stuff yielded by the gen/iter objects. ... Or perhaps another way to achieve this flattening effect? ...
    (comp.lang.python)
  • Re: i=2; lst=[i**=2 while i<1000]
    ... yield start ... the trick is to create two independent iterators, using itertools.tee, one of ... which is consumed internally in the funcfor i in iteratorsgenerator ...
    (comp.lang.python)
  • Re: Class and Iterator Design Question
    ... basically integrating the enumerator ... That sounds unnecesarily complex. ... Anyway, yes, just like a Generator, and for all the usage of yield, not ...
    (comp.lang.ruby)
  • Re: Python syntax in Lisp and Scheme
    ... "yield" is the keyword that makes it into a generator. ... For the latter in Python, ... and compile it for subsequent execution, ...
    (comp.lang.python)

Loading