Chris Chase S1A chris.chase@jhuapl.edu
Wed, 3 Apr 1996 09:41:26 -0500

>>>>> "KH" == Konrad HINSEN <hinsenk@ere.umontreal.ca> writes:

KH> The recently introduced slice notation (a:b etc.) has greatly improved
KH> readability of slice indexing, but is has also lead to the disappearance
KH> of the old Slice() objects (they are still there, but are not accepted
KH> as indices any more) and thereby important functionality: it is no
KH> longer possible to construct index expressions containing slices
KH> dynamically.

KH> There are basically three possible solutions:

KH> 1) Make the : notation legal everywhere. That would make slice objects
KH>    first-class objects like anything else in Python. You could create
KH>    them, assign them to variables, make them elements of lists, tuples,
KH>    or arrays, etc. It would then make sense to make them real sequence
KH>    objects that can be subscripted, used in for-loops, converted to
KH>    lists or tuples etc.

KH> 2) Reintroduce the old Slice() notation for the new slice objects.
KH>    The consequences would be the same as above, but with a less
KH>    uniform syntax. I don't really see the point of doing this.

KH> 3) Keep slice objects restricted to index expressions, but create
KH>    some way to make them act on a dynamically specified axis. Then
KH>    the example given above could be handled by iteratively indexing
KH>    along the axes. Less elegant, but better than nothing.

KH> My personal favourite is 1), and I can't see any disadvantage in
KH> this. But that makes me think about why slice objects were restricted
KH> to subscripts in the first place. Was there a good reason for that, or
KH> was it just the desire to make the smallest possible change to Python
KH> syntax?

There are problems with this as I found when initially considering
such a possibility.  If ":" notation is allowed wherever a "test"
expression can occur then there can be ambiguity with statements where
":" is used to introduce a compound statement, i.e. in "for" or "if"

I think that we will have to go with option (2).  However, the
interface to Slice() should change to duplicate ":" rather than have
the old interface.


MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org