summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2024-06-26 02:19:55 -0700
committerKaz Kylheku <kaz@kylheku.com>2024-06-26 02:19:55 -0700
commit8e8258ed0fab433fd6fb8d5e8480eabae9a807ca (patch)
tree90baadbaedcfb3b3e6a6e740a112f69a4e4c5638
parent7412b622b495b22ccb39233ad1819ea0cdf3d167 (diff)
downloadtxr-8e8258ed0fab433fd6fb8d5e8480eabae9a807ca.tar.gz
txr-8e8258ed0fab433fd6fb8d5e8480eabae9a807ca.tar.bz2
txr-8e8258ed0fab433fd6fb8d5e8480eabae9a807ca.zip
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.
-rw-r--r--lib.c6
-rw-r--r--tests/012/iter.tl13
2 files changed, 19 insertions, 0 deletions
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
@@ -95,15 +95,28 @@
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)))