sholden at holdenweb.com
Fri Aug 24 01:00:34 CEST 2001
"Bengt Richter" <bokr at accessone.com> wrote in message
news:3b856114.272278696 at wa.news.verio.net...
> On Thu, 23 Aug 2001 14:24:40 +0200, "Juan Valiño" <juanv at posta.unizar.es>
> >Many times I want to extract a sublist and I have the initial position p
> >plus the length n.
> >So I do:
> >Many times the initial position p is an expression. Hence, I have to
> >repeat it tediously (and with a possible lost of performance) or assign
> >previously to a variable. The last is boring and is a little trick out of
> >the logic of the program
> >My proposal is to introduce a new operator, for instance # (count):
> >v[5 # 2]
> >Extract 2 elements starting at 5: [ v, v ]. Equivalent to v[5:5+2]
> >v[5 # -2]
> >Extract 2 elements ending at (but not including the) 5: [ v, v ].
> >Equivalent to v[5-2:5]
> >I think that this little syntactic sugar allows programs more compact and
> >readable. Also, I had less "start and end point paranoias". I suppose
> >the implementation is easy and the current programs are not affected at
> '#' is a comment delimiter which would make that usage awful. But I think
> could be possible and also
> would be equivalent to
> slice_parameter_value_to_use = the_other_slice_parameter op
> This might have interesting (maybe even useful ;-) consequences
> for ops other than + and - and might not be that bad to implement, since
> op= tokens are distinct.
If I can remember my Icon correctly its slicing mechanism recognised signs
as significant, so
meant take a slice of length b starting at position a, whereas
took a slice from positions a to b. Of course, strictly speaking this could
induce code breakage in Python -- although the plus sign is redundant in
such existing code, it might occur. Shame the issue wasn't addressed when
slices were introduced, though.
More information about the Python-list