Infinity syntax. Re: Bug in string.find; was...
Kay Schluehr
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
n->infinity
That enables consistent arithmetics:
!0+k = lim n+k -> !0
n->infinity
!0/k = lim n/k -> !0 for k>0,
n->infinity -!0 for k<0
ZeroDevisionError for k==0
etc.
In Python notation:
>>> !0
!0
>>> !0+1
!0
>>> !0>n # if n is int
True
>>> !0/!0
Traceback (...)
...
UndefinedValue
>>> !0 - !0
Traceback (...)
...
UndefinedValue
>>> -!0
-!0
>>> range(9)[4:!0] == range(9)[4:]
True
>>> range(9)[4:-!0:-1] == range(5)
True
Life can be simpler with unbound limits.
Kay
More information about the Python-list
mailing list