Proposed PEP: New style indexing, was Re: Bug in slice type

Bryan Olson fakeaddress at nowhere.org
Wed Aug 24 09:28:16 EDT 2005


Paul Rubin wrote:
 > Bryan Olson writes:
 >
 >>     seq[3 : -4]
 >>
 >>we write:
 >>
 >>     seq[3 ; $ - 4]
 >
 >
 > +1

I think you're wrong about the "+1". I defined '$' to stand for
the length of the sequence (not the address of the last
element).


 >>When square-brackets appear within other square-brackets, the
 >>inner-most bracket-pair determines which sequence '$' describes.
 >>(Perhaps '$$' should be the length of the next containing
 >>bracket pair, and '$$$' the next-out and...?)
 >
 > Not sure.  $1, $2, etc. might be better, or $<tag> like in regexps, etc.

Sounds reasonable.


[...]
 > Hmm, tuples are hashable and are already valid indices to mapping
 > objects like dictionaries.  Having slices means an object can
 > implement both the mapping and sequence interfaces.  Whether that's
 > worth caring about, I don't know.

Yeah, I thought that alternative might break peoples code, and
it turns out it does.


-- 
--Bryan



More information about the Python-list mailing list