summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2024-02-28 19:22:16 -0800
committerKaz Kylheku <kaz@kylheku.com>2024-02-28 19:22:16 -0800
commit2a1d54acebc62771ec1d67e942449cc268c0b568 (patch)
treee16ee53ea39a51e9deeb894a7f3ec7032f52782a
parent4f106ec38761c223304b74acfae490127beca464 (diff)
downloadtxr-2a1d54acebc62771ec1d67e942449cc268c0b568.tar.gz
txr-2a1d54acebc62771ec1d67e942449cc268c0b568.tar.bz2
txr-2a1d54acebc62771ec1d67e942449cc268c0b568.zip
partition-by: replace sequence traversal with iter.
* lib.c (partition_by_func): The seq object is now an iter object: use iter_more, iter_item and iter_step rather than non-null test, car and cdr. (partition_by): Obtain iterator for sequence using iter_begin, and use that in its place.
-rw-r--r--lib.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/lib.c b/lib.c
index 8418b99a..c4957490 100644
--- a/lib.c
+++ b/lib.c
@@ -3897,15 +3897,17 @@ val tuples_star(val n, val seq, val fill)
static val partition_by_func(val func, val lcons)
{
seq_build_t bu;
- us_cons_bind (flast, seq, lcons);
+ us_cons_bind (flast, iter, lcons);
val fnext = nil;
- seq_build_init(lit("partition-by"), &bu, seq);
+ seq_build_init(lit("partition-by"), &bu, iter);
- seq_add(&bu, pop(&seq));
+ seq_add(&bu, iter_item(iter));
+ iter = iter_step(iter);
+
+ while (iter_more(iter)) {
+ val next = iter_item(iter);
- while (seq) {
- val next = car(seq);
fnext = funcall1(func, next);
if (!equal(flast, fnext))
@@ -3913,26 +3915,27 @@ static val partition_by_func(val func, val lcons)
seq_add(&bu, next);
- seq = cdr(seq);
+ iter = iter_step(iter);
flast = fnext;
}
- us_rplacd(lcons, if2(seq,
+ us_rplacd(lcons, if2(iter_more(iter),
make_lazy_cons_car_cdr(us_lcons_fun(lcons),
- fnext, seq)));
+ fnext, iter)));
us_rplaca(lcons, seq_finish(&bu));
return nil;
}
val partition_by(val func, val seq)
{
+ val iter = iter_begin(seq);
seq = nullify(seq);
- if (!seq)
+ if (!iter_more(iter))
return nil;
return make_lazy_cons_car_cdr(func_f1(func, partition_by_func),
- funcall1(func, car(seq)), seq);
+ funcall1(func, iter_item(iter)), iter);
}
static val partition_if_countdown_funv(val envcons, varg args)