PEP 284, Integer for-loops (code bash?)

Laura Creighton lac at strakt.com
Sat Mar 9 13:09:25 EST 2002


> Laura Creighton writes:
> > I think that it
> > would have been nice if when Guido was designing the language he
> > used Haskall's syntax for loops.  But he didn't.
> 
> I *still* haven't found time to learn Haskall, and a quick browse of the 
> docs didn't get me anywhere. Can you summarize what Haskall's syntax
> for loops IS? I realize this is a little off topic, but I'm curious.
> 
> -- Michael Chermside
> 

1.  Michael! Your Computer thinks its April!  You are making
    python archives one month ahead of yourself!
    (see: http://mail.python.org/pipermail/python-list/2002-April/091714.html)

2. Haskell, which I mispelt, shame on me, I know better, is a
   functional language.  It has functional syntax - don't go there looking
   for a 'for loop'.  However, it also has list comprehensions, (which is
   where we got them from, I think).  So, what I meant was 'I wish that 
   Guido had used Haskell's syntax for arithmetic sequences in Python's 
   for loops'.  That is as follows:

   [1..10]     => [1,2,3,4,5,6,7,8,9,10]
   [1,3..8]    => [1,3,5,7]
   [1,3..]     => [1,3,5,7,9, ... (infinite sequence)

   This is not restricted to numbers, char works great.
   
   ['A','B'..'Z'] => the upper case letters in English in alphabetical order

   you can also roll your own:
   
   If you make a user-defined enumerated class, such as statWisdom,
   you can use it like this:

   [inane..enlightened]  => [inane, stupid, idiotic, uneducated, 
                             educated, learned, wise, enlightened]

I have probably forgotten something, somebody else can add it.

3.  Make the time to learn Haskell.  It is simply too much fun.

Laura Creighton





More information about the Python-list mailing list