From 8e8258ed0fab433fd6fb8d5e8480eabae9a807ca Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 26 Jun 2024 02:19:55 -0700 Subject: iter-begin: handle FLNUM. * lib.c (iter_begin, iter_more, iter_item, iter_step, iter_reset, copy_iter): Handle FLNUM like NUM, so that we don't wastefully return a dynamic iterator object. * tests/012/iter.tl: Test cases for numeric and character iteration. Test cases for iter-begin on some basic types. copy-iter test for floats. --- lib.c | 6 ++++++ tests/012/iter.tl | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib.c b/lib.c index b2e00828..42ab5491 100644 --- a/lib.c +++ b/lib.c @@ -1305,6 +1305,7 @@ val iter_begin(val obj) case CHR: case NUM: case BGNUM: + case FLNUM: return obj; case COBJ: if (obj_struct_p(obj)) { @@ -1351,6 +1352,7 @@ val iter_more(val iter) return if2(c_ch(iter) <= 0x10FFFF, t); case NUM: case BGNUM: + case FLNUM: return t; case COBJ: if (iter->co.cls == seq_iter_cls) @@ -1378,6 +1380,7 @@ val iter_item(val iter) case CHR: case NUM: case BGNUM: + case FLNUM: return iter; case COBJ: if (iter->co.cls == seq_iter_cls) @@ -1407,6 +1410,7 @@ val iter_step(val iter) case CHR: case NUM: case BGNUM: + case FLNUM: return plus(iter, one); case CONS: case LCONS: @@ -1454,6 +1458,7 @@ val iter_reset(val iter, val obj) case CHR: case NUM: case BGNUM: + case FLNUM: return obj; case COBJ: if (iter->co.cls == seq_iter_cls) @@ -1514,6 +1519,7 @@ val copy_iter(val iter) case CHR: case NUM: case BGNUM: + case FLNUM: return iter; case COBJ: if (iter->co.cls == seq_iter_cls) { diff --git a/tests/012/iter.tl b/tests/012/iter.tl index 67e9875e..9b12d49c 100644 --- a/tests/012/iter.tl +++ b/tests/012/iter.tl @@ -94,16 +94,29 @@ 115792089237316195423570985008687907853269984665640564039457584007913129639934 115792089237316195423570985008687907853269984665640564039457584007913129639933)) +(mtest + (take 3 (list-seq 1.0)) (1.0 2.0 3.0) + (take 3 (list-seq #\a)) (#\a #\b #\c) + (take 3 (list-seq 1)) (1 2 3)) + (mtest (str-seq (iter-cat "abc" "def" "ghi" #\j..(succ #\z))) "abcdefghijklmnopqrstuvwxyz" (iter-cat) nil (list-seq (iter-cat nil)) nil) +(mtest + (iter-begin nil) nil + (iter-begin '(1 2 3)) (1 2 3) + (iter-begin 42) 42 + (iter-begin 3.14) 3.14 + (iter-begin #\a) #\a) + (mtest (copy-iter nil) nil (copy-iter '(1 2 3)) (1 2 3) (copy-iter 42) 42 + (copy-iter 3.14) 3.14 (copy-iter #\a) #\a) (each ((obj '("abcde" #(0 1 2 3 4) "a".."z" 0..9 1.0..10.0))) -- cgit v1.2.3