diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-01-17 11:11:29 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-01-17 11:11:29 -0800 |
commit | 4eca98b2703d71eec4f47e9b9300a825722bd1cc (patch) | |
tree | c572ee397ebc8ac6a223c5ef554622a408d069ca | |
parent | 1c3cecbb1a75bae5c04e5c32ba0a259b33a74c23 (diff) | |
download | txr-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.
-rw-r--r-- | lib.c | 23 |
1 files changed, 14 insertions, 9 deletions
@@ -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)); } |