enhancing slicing

Tim Peters tim.one at home.com
Fri Aug 24 01:00:04 EDT 2001


[Steve Holden]
> If I can remember my Icon correctly its slicing mechanism recognised
> signs as significant,

Right, but not quite as you remember it.

> so
>
>     seq[a:+b]
>
> meant take a slice of length b starting at position a,

Unary + is nothing special; the syntax Icon uses is

    seq[a +: b]

as sugar for

    seq[a : a+b]

but evaluating "a" only once (significant if there are side-effects);
likewise

    seq[a -: b]

as sugar for

    seq[a-b : a]

Python *could* do the same without breaking anything.  I told Guido so often
that he borrowed sequence slicing from Icon that he *almost* remembers it
that way too <wink>.





More information about the Python-list mailing list