summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-01-17 11:11:29 -0800
committerKaz Kylheku <kaz@kylheku.com>2016-01-17 11:11:29 -0800
commit4eca98b2703d71eec4f47e9b9300a825722bd1cc (patch)
treec572ee397ebc8ac6a223c5ef554622a408d069ca /lib.c
parent1c3cecbb1a75bae5c04e5c32ba0a259b33a74c23 (diff)
downloadtxr-4eca98b2703d71eec4f47e9b9300a825722bd1cc.tar.gz
txr-4eca98b2703d71eec4f47e9b9300a825722bd1cc.tar.bz2
txr-4eca98b2703d71eec4f47e9b9300a825722bd1cc.zip
partition* bugfix: ignore negative indices consistently.
* lib.c (partition_star): Eliminate strange behaviors when a negative index is given as an argument.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c23
1 files changed, 14 insertions, 9 deletions
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));
}