PEP 276 Simple Iterator for ints (fwd)

Ben Wolfson wolfson at uchicago.edu
Thu Nov 29 07:00:46 CET 2001


Here is the really killer proposal everyone's been waiting for.  What we
need is a for-loop with the following syntax:

for lower < (func) < upper named "name":

<= would also be permissible; the parentheses around func are to aid in
disambiguation (for instance, in a lambda expression, it would otherwise
be impossible to determine where it ended).  What this would do is simple.
func would be a function of one argument accepting an integer and
returning an integer-like result.  It would be called starting with 0 and
then with successively incremented values until the value returned is no 
longer in the specified range.  Otherwise, that value would be stored in 
the local scope with the name specified by the "named" part.  "named"
would be a pseudo-keyword like "as".  This would allow all sorts of
wacky loop indexing.  For example, if you wanted an infinite loop with 
an index that alternated between 0 and 1, nothing could be simpler:

for 0 <= (lambda x: int(math.sin(math.pi * x/2.))**2) <= 1 named "i":
    #body of loop

And the indexing variable could be a class instance, a tuple, anything
you like, as long as it supports < or <=!  Imagine the largely useless
possibilities!

I think the issue is settled.

-- 
BTR    
Why does this Wolfson person see fit to clutter up Usenet with such
absurd nonsense?
  -- Bob Cunningham in <km4butor1ke8f5et2f3p5h80jh521cn2sk at 4ax.com>



More information about the Python-list mailing list