From 4eca98b2703d71eec4f47e9b9300a825722bd1cc Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 17 Jan 2016 11:11:29 -0800 Subject: partition* bugfix: ignore negative indices consistently. * lib.c (partition_star): Eliminate strange behaviors when a negative index is given as an argument. --- lib.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'lib.c') diff --git a/lib.c b/lib.c index 6168bb52..0cff2bb5 100644 --- a/lib.c +++ b/lib.c @@ -2021,18 +2021,23 @@ val partition_star(val seq, val indices) if (indices == zero) return cons(nullify(rest(seq)), nil); - if (!seqp(indices)) { + if (!seqp(indices)) indices = cons(indices, nil); - } else { - while (eql(car(indices), base)) { - seq = nullify(cdr(seq)); - if (!seq) - return nil; - base = plus(base, one); - pop(&indices); - } + + while (indices && lt(car(indices), zero)) + pop(&indices); + + while (indices && eql(car(indices), base)) { + seq = nullify(cdr(seq)); + if (!seq) + return nil; + base = plus(base, one); + pop(&indices); } + if (!indices) + return cons(seq, nil); + return make_lazy_cons(func_f1(cons(seq, cons(indices, base)), partition_star_func)); } -- cgit v1.2.3