Please comment on Draft PEP for Enhanced Generators

Michael Chermside mcherm at destiny.com
Wed Jan 30 11:36:10 EST 2002


One minor detail:

>  def ints(cnt=0, limit=None):
> 	'Generate an integer sequence starting a zero or cnt upto limit or infinity'
>         while not limit or cnt < limit:
> 	    yield cnt
> 	    cnt += 1
> 
> 

Calling ints(0,0) should probably not yield the sequence:
     0, 1, 2, 3, ...
I would instead expect an empty sequence! I would suggest this tiny 
modification:

    def ints(cnt=0, limit=None):
       """Generate an integer sequence starting a zero or cnt upto limit
       or infinity"""
       while limit is None or cnt < limit:
          yield cnt
          cnt += 1


As for my overall thoughts:

    * The new built-ins are all good ideas. Do them immediately. The only
      unnecessary bit (that other still-under-consideration PEPs contain
      other ways of achieving ints()) is already mentioned in your PEP.

    * Generator comprehensions seem to be potentially useful, though I'm
      not really sure. The syntax is nice, the only issue is whether
      their utility is sufficient to meet the bar to be worth extending
      the language. I'm on the fence.

    * Two-way generator parameter passing seems awefully bold. To my
      mind, one of the great things about generators is that they meet
      the (very simple) definition of an iterator. With this, they no
      longer do. I like lazy consumers -- really I do -- but I'd rather
      be conservative about putting something like this in the language.


And hey... great work in writing these up!

-- Michael Chermside





More information about the Python-list mailing list