From 1291aa76a9c85ac50bc5ebe968fd332bdfe80af0 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 27 Feb 2024 20:48:00 -0800 Subject: tuples: convert tuple generation to seq_build. * lib.c (tuples_func): Replace list accumulation with make_like with seq_build. * tests/012/seq.tl: Fix one test case here which no longer errors out. It produces a tuple which is not a string, due to the inclusion of a non-character object. --- lib.c | 11 +++++++---- tests/012/seq.tl | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib.c b/lib.c index a0c26ff0..11c579c2 100644 --- a/lib.c +++ b/lib.c @@ -3785,24 +3785,27 @@ val lazy_flatcar(val tree) static val tuples_func(val n, val lcons) { - list_collect_decl (out, ptail); + seq_build_t bu; us_cons_bind (iter_in, fill, lcons); val iter = iter_in; val count; + seq_build_init(lit("tuples"), &bu, iter); + for (count = n; count != zero && iter_more(iter); count = minus(count, one), iter = iter_step(iter)) - ptail = list_collect(ptail, iter_item(iter)); + seq_add(&bu, iter_item(iter)); if (!missingp(fill)) for (; gt(count, zero); count = minus(count, one)) - ptail = list_collect(ptail, fill); + seq_add(&bu, fill); if (iter_more(iter)) us_rplacd(lcons, make_lazy_cons_car_cdr(us_lcons_fun(lcons), iter, fill)); else us_rplacd(lcons, nil); - us_rplaca(lcons, make_like(out, iter_in)); + + us_rplaca(lcons, seq_finish(&bu)); return nil; } diff --git a/tests/012/seq.tl b/tests/012/seq.tl index 407af84a..144c6971 100644 --- a/tests/012/seq.tl +++ b/tests/012/seq.tl @@ -263,7 +263,7 @@ list) (test - (lforce (tuples 2 "abc" 3)) :error) + (lforce (tuples 2 "abc" 3)) ("ab" (#\c 3))) (test (take 3 (tuples 3 (range 0))) ((0 1 2) (3 4 5) (6 7 8))) -- cgit v1.2.3