Make cyclic slicing logic consistent
dloscutoff opened this issue · 1 comments
dloscutoff commented
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.)
dloscutoff commented
Core principles:
H
andS
with nonnegative rhs should return something whose length equals the rhsaSb
should be equivalent toR((Ra)Hb)
for alla
,b
- Unless it is empty, the result of
H
should always start with the first element of the lhs; similarly, the result ofS
(if nonempty) should always end with the last element of the lhs
Definitely bugged:
10 S 7
should return0101010
; currently returns01010
Outstanding questions:
- Should
@<
cycle when given an rhs greater than the length of the lhs, particularly since this is the same behavior asH
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 forS
.