summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2024-07-10 02:29:34 -0700
committerKaz Kylheku <kaz@kylheku.com>2024-07-10 02:29:34 -0700
commit6e020df833a86acf3aba5d6c0caf139720ab2204 (patch)
treebf692c1efe216c8168696ff8ff83d3a5228cca6d
parent588cfc99a8c9ca5eed03caae6147ae1e10519145 (diff)
downloadtxr-6e020df833a86acf3aba5d6c0caf139720ab2204.tar.gz
txr-6e020df833a86acf3aba5d6c0caf139720ab2204.tar.bz2
txr-6e020df833a86acf3aba5d6c0caf139720ab2204.zip
split**: split for far negative indices.
* lib.c (split_star_func): In empty index case, convert sequence via sub(seq, zero, t), so that ranges are properly expanded. This was done in split_func and partition_func in recent commits. * tests/012/seq.tl: Test cases added.
-rw-r--r--lib.c2
-rw-r--r--tests/012/seq.tl32
2 files changed, 33 insertions, 1 deletions
diff --git a/lib.c b/lib.c
index 675a5f47..4e21108b 100644
--- a/lib.c
+++ b/lib.c
@@ -4312,7 +4312,7 @@ static val split_star_func(val base, val lcons)
us_rplaca(lcons, first);
}
} else {
- us_rplaca(lcons, seq);
+ us_rplaca(lcons, sub(seq, zero, t));
us_rplacd(lcons, nil);
}
break;
diff --git a/tests/012/seq.tl b/tests/012/seq.tl
index f81c4046..0067a4c1 100644
--- a/tests/012/seq.tl
+++ b/tests/012/seq.tl
@@ -1107,6 +1107,8 @@
(split 2..5 '(2 3)) ((2 3) (4) nil))
(mtest
+ (split* nil -3) nil
+ (split* nil -2) nil
(split* nil -1) nil
(split* nil 0) nil
(split* nil 1) nil
@@ -1115,6 +1117,8 @@
(split* nil '(1)) nil)
(mtest
+ (split* #() -3) nil
+ (split* #() -2) nil
(split* #() -1) nil
(split* #() 0) nil
(split* #() 1) nil
@@ -1123,6 +1127,8 @@
(split* #() '(1)) nil)
(mtest
+ (split* "" -3) nil
+ (split* "" -2) nil
(split* "" -1) nil
(split* "" 0) nil
(split* "" 1) nil
@@ -1131,6 +1137,8 @@
(split* "" '(1)) nil)
(mtest
+ (split* 2..2 -3) nil
+ (split* 2..2 -2) nil
(split* 2..2 -1) nil
(split* 2..2 0) nil
(split* 2..2 1) nil
@@ -1139,6 +1147,9 @@
(split* 2..2 '(1)) nil)
(mtest
+ (split* '(a) -4) ((a))
+ (split* '(a) -3) ((a))
+ (split* '(a) -2) ((a))
(split* '(a) -1) (nil nil)
(split* '(a) 0) (nil nil)
(split* '(a) 1) ((a) nil)
@@ -1148,6 +1159,9 @@
(split* '(a) '(1)) ((a) nil))
(mtest
+ (split* #(a) -4) (#(a))
+ (split* #(a) -3) (#(a))
+ (split* #(a) -2) (#(a))
(split* #(a) -1) (#() #())
(split* #(a) 0) (#() #())
(split* #(a) 1) (#(a) #())
@@ -1157,6 +1171,9 @@
(split* #(a) '(1)) (#(a) #()))
(mtest
+ (split* "a" -4) ("a")
+ (split* "a" -3) ("a")
+ (split* "a" -2) ("a")
(split* "a" -1) ("" "")
(split* "a" 0) ("" "")
(split* "a" 1) ("a" "")
@@ -1166,6 +1183,9 @@
(split* "a" '(1)) ("a" ""))
(mtest
+ (split* 2..3 -4) ((2))
+ (split* 2..3 -3) ((2))
+ (split* 2..3 -2) ((2))
(split* 2..3 -1) (nil nil)
(split* 2..3 0) (nil nil)
(split* 2..3 1) ((2) nil)
@@ -1175,6 +1195,9 @@
(split* 2..3 '(1)) ((2) nil))
(mtest
+ (split* '(a b) -4) ((a b))
+ (split* '(a b) -3) ((a b))
+ (split* '(a b) -2) (nil (b))
(split* '(a b) -1) ((a) nil)
(split* '(a b) 0) (nil (b))
(split* '(a b) 1) ((a) nil)
@@ -1188,6 +1211,9 @@
(split* '(a b) '(-1 2)) ((a) nil)) ;; questionable
(mtest
+ (split* #(a b) -4) (#(a b))
+ (split* #(a b) -3) (#(a b))
+ (split* #(a b) -2) (#() #(b))
(split* #(a b) -1) (#(a) #())
(split* #(a b) 0) (#() #(b))
(split* #(a b) 1) (#(a) #())
@@ -1201,6 +1227,9 @@
(split* #(a b) '(-1 2)) (#(a) #())) ;; questionable
(mtest
+ (split* "ab" -4) ("ab")
+ (split* "ab" -3) ("ab")
+ (split* "ab" -2) ("" "b")
(split* "ab" -1) ("a" "")
(split* "ab" 0) ("" "b")
(split* "ab" 1) ("a" "")
@@ -1214,6 +1243,9 @@
(split* "ab" '(-1 2)) ("a" "")) ;; questionable
(mtest
+ (split* 2..4 -4) ((2 3))
+ (split* 2..4 -3) ((2 3))
+ (split* 2..4 -2) (() (3))
(split* 2..4 -1) ((2) ())
(split* 2..4 0) (nil (3))
(split* 2..4 1) ((2) nil)