[Python-checkins] python/nondist/peps pep-0322.txt,1.8,1.9
rhettinger at users.sourceforge.net
rhettinger at users.sourceforge.net
Tue Oct 28 17:39:25 EST 2003
Update of /cvsroot/python/python/nondist/peps
In directory sc8-pr-cvs1:/tmp/cvs-serv29959
Modified Files:
pep-0322.txt
Log Message:
No one likes the name inreverse().
Index: pep-0322.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0322.txt,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** pep-0322.txt 28 Oct 2003 21:21:31 -0000 1.8
--- pep-0322.txt 28 Oct 2003 22:39:22 -0000 1.9
***************
*** 47,51 ****
========
! Add a builtin function called *inreverse()* that makes a reverse
iterator over sequence objects that support __getitem__() and
__len__().
--- 47,51 ----
========
! Add a builtin function called *ireverse()* that makes a reverse
iterator over sequence objects that support __getitem__() and
__len__().
***************
*** 53,71 ****
The above examples then simplify to::
! for i in inreverse(xrange(n)):
print seqn[i]
::
! for elem in inreverse(seqn):
print elem
The core idea is that the clearest, least error-prone way of specifying
reverse iteration is to specify it in a forward direction and then say
! *inreverse*.
The implementation could be as simple as::
! def inreverse(x):
i = len(x)
while i > 0:
--- 53,71 ----
The above examples then simplify to::
! for i in ireverse(xrange(n)):
print seqn[i]
::
! for elem in ireverse(seqn):
print elem
The core idea is that the clearest, least error-prone way of specifying
reverse iteration is to specify it in a forward direction and then say
! *ireverse*.
The implementation could be as simple as::
! def ireverse(x):
i = len(x)
while i > 0:
***************
*** 84,88 ****
* *backwards* -- more pithy, less explicit
! * *ireverse* -- reminiscent of imap(), izip(), and ifilter()
--- 84,91 ----
* *backwards* -- more pithy, less explicit
! * *inreverse* -- no one seems to like this one except me
!
! The name *reverse* is not a candidate because it duplicates the name
! of the list.reverse() which mutates the underlying list.
***************
*** 90,94 ****
==============
! Objects may optionally provide an *__inreverse__* method that returns
a custom reverse iterator.
--- 93,97 ----
==============
! Objects may optionally provide an *__ireverse__* method that returns
a custom reverse iterator.
***************
*** 141,145 ****
be run in a forward direction but is less intuitive and rarely
presented that way in literature. The replacement code
! ``for i in inreverse(xrange(1, len(x)))`` is much easier
to verify visually.
--- 144,148 ----
be run in a forward direction but is less intuitive and rarely
presented that way in literature. The replacement code
! ``for i in ireverse(xrange(1, len(x)))`` is much easier
to verify visually.
***************
*** 159,163 ****
A simpler, but limited alternative is to create a builtin that takes
the same arguments as range() but returns a reverse iterator over the
! range. The idea is that much of the benefit of inreverse() comes
reducing the intellectual effort it takes to express the arguments for
[x]range() when going backwards. A good name is needed for this
--- 162,166 ----
A simpler, but limited alternative is to create a builtin that takes
the same arguments as range() but returns a reverse iterator over the
! range. The idea is that much of the benefit of ireverse() comes
reducing the intellectual effort it takes to express the arguments for
[x]range() when going backwards. A good name is needed for this
***************
*** 168,172 ****
====================
! Several variants were submitted that attempted to apply inreverse()
to all iterables by running the iterable to completion, saving the
results, and then returning a reverse iterator over the results.
--- 171,175 ----
====================
! Several variants were submitted that attempted to apply ireverse()
to all iterables by running the iterable to completion, saving the
results, and then returning a reverse iterator over the results.
More information about the Python-checkins
mailing list