diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-02-27 20:48:00 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-02-27 20:48:00 -0800 |
commit | 1291aa76a9c85ac50bc5ebe968fd332bdfe80af0 (patch) | |
tree | 1b60d04d27b3d82672172188c6778bc240e8af2d | |
parent | b3a440ca242a07ed86f89d06208f15757d947e12 (diff) | |
download | txr-1291aa76a9c85ac50bc5ebe968fd332bdfe80af0.tar.gz txr-1291aa76a9c85ac50bc5ebe968fd332bdfe80af0.tar.bz2 txr-1291aa76a9c85ac50bc5ebe968fd332bdfe80af0.zip |
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.
-rw-r--r-- | lib.c | 11 | ||||
-rw-r--r-- | tests/012/seq.tl | 2 |
2 files changed, 8 insertions, 5 deletions
@@ -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))) |