Dumb python questions

Paul Rubin phr-n2001 at nightsong.com
Sat Aug 18 17:50:49 EDT 2001


"Alex Martelli" <aleaxit at yahoo.com> writes:
> > Maybe in Python 2.2 they can make it into an iterator.  That would be
> > the right way to deal with this problem.
> 
> Yep, but iterators weren't around when xrange was introduced.  The
> "do the right thing" (MIT approach, big-design-up-front approach --
> see Gabriel's article as mentioned in my last post) would of course
> have been to stop the world until iterators were designed -- the "worse
> is better" (NJ approach, just-in-time-design approach, Python's
> approach) is incremental and adaptive.  xrange started out VERY
> ambitious -- used to do all sort of things to mimic the behavior of
> the list it 'represented'.  Turns out it's basically only used for the
> purpose of iterating -- so it was simplified by removing most of
> its complications, and there may be iterators to take its place now.

The Scheme approach is "globally" incremental but locally "do the
right thing".  That is, early versions of Scheme didn't have macros--
they were added later, an example of incremental design.  The REASON
early Scheme didn't have macros wasn't because no one wanted them, but
because the designers weren't sure what the best approach was.  So a
bunch of different macro implementations were tested in various Scheme
dialects and then they settled on one and put it in the standard.
They didn't add something to the standard and then change it later.

The current lambda expression in Python seems almost a Perl-ism: one says

   lambda x: x*x      # anonymous squaring function

instead of

  lambda x: return x*x   # make it more like a real function

Is it just to save the keystrokes of typing "return" that the
functionality is so limited?  I don't see any reason not to be able to
put a real multi-statement procedure under a lambda:

   lambda x:
     if x < 0: return x*x
     else: return x*x*x

Maybe that can be added without breaking existing code, but why not
just do it right the first time?  It's not exactly a "big design up
front" to do the obvious thing.



More information about the Python-list mailing list