enhancing slicing

Eyal Lotem eyal at hyperroll.com
Sat Aug 25 15:03:12 EDT 2001


Marcin 'Qrczak' Kowalczyk wrote:

> Thu, 23 Aug 2001 20:24:25 GMT, Bengt Richter <bokr at accessone.com> pisze:
> 
>> I.e.,
>>    v[a:+=b]
>> and
>>    v[-=b:a]
>> would be equivalent to
>>    v[a:a+b]
>> and
>>    v[a-b:a]
>> IOW,
>>    op=slice_parameter
>> implies
>>    slice_parameter_value_to_use = the_other_slice_parameter op
>>    slice_parameter
> 
> Since a += b is almost equivalent to a = a+b, a:a+b should be spelled
> a+:b.
IMHO, += is right to introduce, because it represents an abstract concept 
of adding into something.
a : a+b represents the abstract concept of a range that has a start and a 
length, rather than a start and an end.
I don't think, however, that a : a*b, or a:a-b represents some basic 
abstract concept that would be nicely represented by syntax.
I would find it nice to support the notion of describing a range with the 
start and size, rather than the start and end myself, because it is a 
useful concept and found to be an easier alternative (perhaps with a syntax 
like: [a:+b]).
This does not mean that [a:-b] or [a:*b] is legal, however, because 
specifying an end and a size, or a start and an end which is a 
multiplication of the start's index does not represent any useful 
(commonly-used) concept.




More information about the Python-list mailing list