diff --git a/lslopt/lslbasefuncs.py b/lslopt/lslbasefuncs.py index b0f986f..80412ea 100644 --- a/lslopt/lslbasefuncs.py +++ b/lslopt/lslbasefuncs.py @@ -1448,7 +1448,14 @@ def llList2ListSlice(src, start, end, stride, slice_idx): end = fi(end) stride = fi(stride) slice_idx = fi(slice_idx) - raise ELSLCantCompute # TODO: Implement llList2ListSlice + if stride <= 0 or slice_idx < -stride or slice_idx > stride - 1: + return [] + # Resolve exclusion range exactly like llList2List, generating a new list. + # NOTE: This bears improvement, by not making an intermediate new list. + src = InternalGetDeleteSubSequence(src, start, end, isGet=True) + if slice_idx < 0: + slice_idx += stride + return src[slice_idx::stride] def llList2ListStrided(lst, start, end, stride): lst = fl(lst) diff --git a/unit_tests/expr.suite/list-funcs-4.lsl b/unit_tests/expr.suite/list-funcs-4.lsl new file mode 100644 index 0000000..f0a8ed2 --- /dev/null +++ b/unit_tests/expr.suite/list-funcs-4.lsl @@ -0,0 +1,21 @@ + "T01" + llList2ListSlice([], 0, -1, 1, 0) ++ "T02" + llList2ListSlice([], 0, 0, 1, 0) ++ "T03" + llList2ListSlice([0,1,2,3,4,5,6], 0, 1, 1, 0) ++ "T04" + llList2ListSlice([0,1,2,3,4,5,6], 0, -1, 3, 0) ++ "T05" + llList2ListSlice([0,1,2,3,4,5,6], 0, -1, 3, 1) ++ "T06" + llList2ListSlice([0,1,2,3,4,5,6], 1, -1, 3, 1) ++ "T07" + llList2ListSlice([0,1,2,3,4,5,6], 2, -1, 3, -1) ++ "T08" + llList2ListSlice([0,1,2,3,4,5,6], 4, 2, 1, 0) ++ "T09" + llList2ListSlice([0,1,2,3,4,5,6], 0, 5, 3, 0) ++ "T10" + llList2ListSlice([0,1,2,3,4,5,6], 0, 5, 3, 1) ++ "T11" + llList2ListSlice([0,1,2,3,4,5,6], 0, 5, 3, 2) ++ "T12" + llList2ListSlice([0,1,2,3,4,5,6], 0, 5, 3, 3) ++ "T13" + llList2ListSlice([0,1,2,3,4,5,6], 0, 5, 3, -1) ++ "T14" + llList2ListSlice([0,1,2,3,4,5,6], 0, 5, 3, -2) ++ "T15" + llList2ListSlice([0,1,2,3,4,5,6], 0, 5, 3, -3) ++ "T16" + llList2ListSlice([0,1,2,3,4,5,6], 0, 5, 3, -4) ++ "T17" + llList2ListSlice([0,1,2,3,4,5,6], 0, 5, 1, 0) ++ "T18" + llList2ListSlice([0,1,2,3,4,5,6], 0, -1, -1, 0) ++ "T19" + llList2ListSlice([0,1,2,3,4,5,6], 0, 6, 2, 0) ++ "T20" + llList2ListSlice([0,1,2,3,4,5,6], 0, 7, 2, 0) ++ "T21" + llList2ListSlice([0,1,2,3,4,5,6], 0, -3, 2, 0) diff --git a/unit_tests/expr.suite/list-funcs-4.out b/unit_tests/expr.suite/list-funcs-4.out new file mode 100644 index 0000000..8970f00 --- /dev/null +++ b/unit_tests/expr.suite/list-funcs-4.out @@ -0,0 +1,67 @@ +[ "T01" +, "T02" +, "T03" +, 0 +, 1 +, "T04" +, 0 +, 3 +, 6 +, "T05" +, 1 +, 4 +, "T06" +, 2 +, 5 +, "T07" +, 4 +, "T08" +, 0 +, 1 +, 2 +, 4 +, 5 +, 6 +, "T09" +, 0 +, 3 +, "T10" +, 1 +, 4 +, "T11" +, 2 +, 5 +, "T12" +, "T13" +, 2 +, 5 +, "T14" +, 1 +, 4 +, "T15" +, 0 +, 3 +, "T16" +, "T17" +, 0 +, 1 +, 2 +, 3 +, 4 +, 5 +, "T18" +, "T19" +, 0 +, 2 +, 4 +, 6 +, "T20" +, 0 +, 2 +, 4 +, 6 +, "T21" +, 0 +, 2 +, 4 +] \ No newline at end of file