I agree that "range(start=x)" is awkward due to the unusual argument handling of "range", and you are also correct that I should have said "an iterable for which iter(range(x, None, step)) behaves as count(n, step)".
I don't see an issue with len and negative indexing raising ValueError and IndexError, respectively.  After all, a negative index on an infinite sequence is just as undefined.
Antony


2014-06-07 12:07 GMT-07:00 Terry Reedy <tjreedy@udel.edu>:
On 6/6/2014 9:59 PM, Neil Girdhar wrote:
That would be great.

What does 'that' refer too? Ram's original proposal, which you quoted, or Antony's counter-proposal, which you also quoted? Ambiguity is the cost of top-posting combined with over-quoting.

Since I already explained what is wrong with Ram's proposal, I will delete it and assume you mean Antony's, which seems to not have arrived on my machine.


On Friday, May 16, 2014 12:16:52 AM UTC-4, Antony Lee wrote:

    Actually, a more reasonable solution would be to have range handle
    keyword arguments and map "range(start=x)"  to "count(x)".

Having a parameter like 'start' mean two different things when passed by position and name is the sort of oddity we try to avoid.

Since "a range object is an immutable, constant attribute, reiterable sequence object" (my earlier post), while count is an iterator, that does not literally work. So I will assume that you mean (looking ahead) 'an iterable sis_range such that iter(sis_range(n, None, step)) is the same as count(n, step)'.


Or,  perhaps more simply, "range(x, None)"

As an expression, stop=None is literally what you mean.

The problem is that range is a finite sequence with a finite length and an indexable end. For instance, range(10)[-1] == 9. What is needed is a new semi_infinite_sequence base class 'SemiInfSeq' that allows (but not requires) infinite length: float('inf') or a new int('inf'). It would also have to disallow negative ints for indexing and slicing. Or perhaps a class factory is needed.

Many infinite iterators whose items can be calculated from index n could be the iterator for a SIS subclass.  A geometric series and the sequence of squares are other examples. This could be a PyPI package.

--
Terry Jan Reedy


_______________________________________________
Python-ideas mailing list
Python-ideas@python.org