summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2024-07-10 01:41:57 -0700
committerKaz Kylheku <kaz@kylheku.com>2024-07-10 01:41:57 -0700
commit2eed172a061a5df56bcc7cfda28b975165db38d3 (patch)
treeea4f652c7134d5ef746ad03ea929ba2951f967c8
parent42f2b87f012ca4980f326b0270b7a0c1fb34f5a0 (diff)
downloadtxr-2eed172a061a5df56bcc7cfda28b975165db38d3.tar.gz
txr-2eed172a061a5df56bcc7cfda28b975165db38d3.tar.bz2
txr-2eed172a061a5df56bcc7cfda28b975165db38d3.zip
split: fix for far negative indices.
* lib.c (split_func): In empty index case, convert sequence via sub(seq, zero, t), so that ranges are properly expanded. This was done in partition_func in the previous commit. * tests/012/seq.tl: Test cases added.
-rw-r--r--lib.c2
-rw-r--r--tests/012/seq.tl28
2 files changed, 29 insertions, 1 deletions
diff --git a/lib.c b/lib.c
index 8b6c261f..675a5f47 100644
--- a/lib.c
+++ b/lib.c
@@ -4270,7 +4270,7 @@ static val split_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 2e825c9a..a6a7b069 100644
--- a/tests/012/seq.tl
+++ b/tests/012/seq.tl
@@ -896,6 +896,8 @@
(interpose 1 "ab") (#\a 1 #\b))
(mtest
+ (split nil -3) nil
+ (split nil -2) nil
(split nil -1) nil
(split nil 0) nil
(split nil 1) nil
@@ -905,6 +907,8 @@
(split nil '(1)) nil)
(mtest
+ (split #() -3) nil
+ (split #() -2) nil
(split #() -1) nil
(split #() 0) nil
(split #() 1) nil
@@ -914,6 +918,8 @@
(split #() '(1)) nil)
(mtest
+ (split "" -3) nil
+ (split "" -2) nil
(split "" -1) nil
(split "" 0) nil
(split "" 1) nil
@@ -922,6 +928,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
@@ -931,6 +939,8 @@
(split 2..2 '(1)) nil)
(mtest
+ (split '(a) -3) ((a))
+ (split '(a) -2) ((a))
(split '(a) -1) (nil (a))
(split '(a) 0) (nil (a))
(split '(a) 1) ((a) nil)
@@ -941,6 +951,8 @@
(split '(a) '(1)) ((a) nil))
(mtest
+ (split #(a) -3) (#(a))
+ (split #(a) -2) (#(a))
(split #(a) -1) (#() #(a))
(split #(a) 0) (#() #(a))
(split #(a) 1) (#(a) #())
@@ -951,6 +963,8 @@
(split #(a) '(1)) (#(a) #()))
(mtest
+ (split "a" -3) ("a")
+ (split "a" -2) ("a")
(split "a" -1) ("" "a")
(split "a" 0) ("" "a")
(split "a" 1) ("a" "")
@@ -961,6 +975,8 @@
(split "a" '(1)) ("a" ""))
(mtest
+ (split 2..3 -3) ((2))
+ (split 2..3 -2) ((2))
(split 2..3 -1) (nil (2))
(split 2..3 0) (nil (2))
(split 2..3 1) ((2) nil)
@@ -971,6 +987,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 (a b))
(split '(a b) -1) ((a) (b))
(split '(a b) 0) (nil (a b))
(split '(a b) 1) ((a) (b))
@@ -984,6 +1003,9 @@
(split '(a b) '(-1 2)) ((a) (b) nil))
(mtest
+ (split #(a b) -4) (#(a b))
+ (split #(a b) -3) (#(a b))
+ (split #(a b) -2) (#() #(a b))
(split #(a b) -1) (#(a) #(b))
(split #(a b) 0) (#() #(a b))
(split #(a b) 1) (#(a) #(b))
@@ -997,6 +1019,9 @@
(split #(a b) '(-1 2)) (#(a) #(b) #()))
(mtest
+ (split "ab" -4) ("ab")
+ (split "ab" -3) ("ab")
+ (split "ab" -2) ("" "ab")
(split "ab" -1) ("a" "b")
(split "ab" 0) ("" "ab")
(split "ab" 1) ("a" "b")
@@ -1010,6 +1035,9 @@
(split "ab" '(-1 2)) ("a" "b" ""))
(mtest
+ (split 2..4 -4) ((2 3))
+ (split 2..4 -3) ((2 3))
+ (split 2..4 -2) (nil (2 3))
(split 2..4 -1) ((2) (3))
(split 2..4 0) (nil (2 3))
(split 2..4 1) ((2) (3))