Re: What about an EXPLICIT naming scheme for built-ins?

From: Jp Calderone (exarkun_at_divmod.com)
Date: 09/03/04


Date: Fri, 03 Sep 2004 10:05:43 -0400
To: python-list@python.org

Carlos Ribeiro wrote:
> Mostly agreed. There is an inconsistence, as sorted() and reversed()
> should return both the same type of result - be it a sequence or a
> iterator.
>
> I propose a slightly different approach. First, proposing a generic
> naming scheme for built-ins is an ambitious goal, to say the least. I
> suggest to keep the focus on this particular issue, if only to avoid a
> lot of debate and flaming. So -- keeping in mind my own suggestion --
> I would like to focus on the particular case at hand:
>
> 1) sorted() and reversed() should return sequences. So sorted() stays
> like it, and reversed() meaning is changed. Now, that could
> potentially break a lot of code, but probably this is not going to
> happen -- because in most situations, reversed() is getting called

   They are new. There is no reason to worry about breaking
compatibility. Why sequences and not iterators? I would prefer the
latter, and it is in keeping with many other recent language
developments (generator comprehensions, itertools module, etc).

>
> 2) add two new builtins, called respectively xsorted() and
> xreversed(), as the iterator versions of sorted() and reversed(). This
> way we keep the existing naming convention for range() and xrange().

   -1. The "x" prefix means "this is a hack". xrange() will become
range() in Python 3.0. The xreadlines module is deprecated already.

   Jp



Relevant Pages

  • Re: Peek inside iterator (is there a PEP about this?)
    ... sequences, either use itertools.chainor put the short ... wrap the iterator in a trivial-to-write ... Then just define your own 'peekzip'. ... raise StopIteration ...
    (comp.lang.python)
  • Re: Do you have real-world use cases for maps None fill-in feature?
    ... And letting iter take multiple sequences or callable/sentinel pairs, ... > Even if there is little use for continuing in correct code, ... > at the state of the iterator in an erroroneous situation would be a benefit. ... (I can see reasons for wanting variations of trying all streams ...
    (comp.lang.python)
  • Re: Peek inside iterator (is there a PEP about this?)
    ... def do_stuff(tasks, params): ... "Any" cannot peek inside the iterator without ... sequences, either use itertools.chainor put the short ... next value, without consuming it? ...
    (comp.lang.python)
  • Re: Do you have real-world use cases for maps None fill-in feature?
    ... >> (which doesn't even need a separate name, since it would be backwards compatible) ... And letting iter take multiple sequences or callable/sentinel pairs, ... if the iterator has ...
    (comp.lang.python)
  • Re: [ x for x in xrange(10) when p(x) ]
    ... > No way -- the itertools module is and remains a PRECIOUS resource. ... > If you want an iterator rather than a list, ... functions and methods that currently return lists are going to return ...
    (comp.lang.python)