Infinity syntax. Re: Bug in string.find; was...
kay.schluehr at gmx.net
Wed Aug 31 16:13:26 CEST 2005
Bengt Richter wrote:
> How about interpreting seq[i] as an abbreviation of seq[i%len(seq)] ?
> That would give a consitent interpretation of seq[-1] and no errors
> for any value ;-)
Cool, indexing becomes cyclic by default ;)
But maybe it's better to define it explicitely:
seq[!i] = seq[i%len(seq)]
Well, I don't like the latter definition very much because it
introduces special syntax for __getitem__. A better solution may be the
introduction of new syntax and arithmetics for positive and negative
infinite values. Sequencing has to be adapted to handle them.
The semantics follows that creating of limits of divergent sequences:
!0 = lim n
That enables consistent arithmetics:
!0+k = lim n+k -> !0
!0/k = lim n/k -> !0 for k>0,
n->infinity -!0 for k<0
ZeroDevisionError for k==0
In Python notation:
>>> !0>n # if n is int
>>> !0 - !0
>>> range(9)[4:!0] == range(9)[4:]
>>> range(9)[4:-!0:-1] == range(5)
Life can be simpler with unbound limits.
More information about the Python-list