dloscutoff/pip

Make cyclic slicing logic consistent

dloscutoff opened this issue · 1 comments

We have four operators (@<, @>, H, and S) that do some kind of slicing, and all of them behave a little differently when the absolute value of the index is greater than the length of the iterable. Analyze, decide on a consistent behavior, and implement it across the board. (Don't forget to test @ with a Range argument, too.)

Core principles:

  • H and S with nonnegative rhs should return something whose length equals the rhs
  • aSb should be equivalent to R((Ra)Hb) for all a, b
  • Unless it is empty, the result of H should always start with the first element of the lhs; similarly, the result of S (if nonempty) should always end with the last element of the lhs

Definitely bugged:

  • 10 S 7 should return 0101010; currently returns 01010

Outstanding questions:

  • Should @< cycle when given an rhs greater than the length of the lhs, particularly since this is the same behavior as H and maybe it's worthwhile to have the different operators behave differently? Same question for @> when given a negative rhs with absolute value greater than the length of the lhs. (Note also that @ with a Range rhs cycles if the upper bound of the Range, or the absolute value of a negative lower bound of the Range, is greater than the length of the lhs.)
  • Is there any reasonable result, other than empty iterable, for H with a negative rhs whose absolute value is greater than the length of the lhs? Same question for S.