From 30d8e9cd89579c557666e2552ce93ed78165ef1b Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 10 Jul 2024 04:15:22 -0700 Subject: partition, split, split*: bug handling negative indices. * lib.c (partition_func, split_func, split_star_func): When negative indices occur after the sequence has already been shortened, the conversion to positivce must take into account the base. This must be added so that the positive index produced is relative to the original length of the input sequence. When index_rebased is calculated, the base is subtracted out again. If we based the positive index off the shortened length, it's as if we are subtracting base twice. * tests/012/seq.tl: Dubious test cases for split* are replaced with the new results that make sense. Additional test cases are added which cover this issue, for not only split* but split and partition. --- lib.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib.c') diff --git a/lib.c b/lib.c index eb4c9b8c..2b246e69 100644 --- a/lib.c +++ b/lib.c @@ -4205,7 +4205,8 @@ static val partition_func(val base, val lcons) if (iter_more(indices)) { val raw_index = iter_item(indices); val index = if3((!opt_compat || opt_compat > 170) && minusp(raw_index), - plus(raw_index, if3(len, len, len = length(seq))), + plus(plus(raw_index, if3(len, len, len = length(seq))), + base), raw_index); val index_rebased = minus(index, base); @@ -4247,7 +4248,7 @@ static val split_func(val base, val lcons) val len = if3(le, le, le = length(seq)); val raw_index = iter_item(indices); val index = if3((!opt_compat || opt_compat > 170) && minusp(raw_index), - plus(raw_index, len), + plus(plus(raw_index, len), base), raw_index); val index_rebased = minus(index, base); @@ -4290,7 +4291,7 @@ static val split_star_func(val base, val lcons) val len = if3(le, le, le = length(seq)); val raw_index = iter_item(indices); val index = if3((!opt_compat || opt_compat > 170) && minusp(raw_index), - plus(raw_index, len), + plus(plus(raw_index, len), base), raw_index); val index_rebased = minus(index, base); -- cgit v1.2.3