summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-06-14 06:38:54 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-06-14 06:38:54 -0700
commit0ca6b880539ca0ebd2faa784e0bab9a928a91332 (patch)
treeef5478af20a198608b48516e1c8d519c451d521d
parentf9cd0b3815083f3827cd00b15e1ccf9a8706ad3c (diff)
downloadtxr-0ca6b880539ca0ebd2faa784e0bab9a928a91332.tar.gz
txr-0ca6b880539ca0ebd2faa784e0bab9a928a91332.tar.bz2
txr-0ca6b880539ca0ebd2faa784e0bab9a928a91332.zip
replace-list: negatives in index-list follow convention.
The index-list replacement isn't following the convention that negative index values reference from the end of the target sequence. Let's fix that. * lib.c (replace_list): Likewise. * txr.1: Documentation updated.
-rw-r--r--lib.c2
-rw-r--r--txr.118
2 files changed, 15 insertions, 5 deletions
diff --git a/lib.c b/lib.c
index 385101cb..01e18b03 100644
--- a/lib.c
+++ b/lib.c
@@ -1438,6 +1438,8 @@ val replace_list(val list, val items, val from, val to)
self, nao);
while (iter && seq_peek(&item_iter, &item) && seq_peek(&wh_iter, &wh)) {
+ if (minusp(wh))
+ wh = plus(wh, len ? len : (len = length(list)));
if (lt(wh, idx)) {
seq_geti(&wh_iter);
seq_geti(&item_iter);
diff --git a/txr.1 b/txr.1
index dd5eb172..7e85020f 100644
--- a/txr.1
+++ b/txr.1
@@ -27017,6 +27017,11 @@ and
.meta index-list
are of different lengths, then the shorter of the two determines
the maximum number of elements which are overwritten.
+Whenever a negative value occurs in
+.meta index-list
+the length of
+.meta sequence
+is added to that value.
Furthermore, similar restrictions apply on
.meta index-list
as under the
@@ -27030,7 +27035,8 @@ furthermore, if
is a list, then
.meta index-list
must
-be monotonically increasing.
+be monotonically increasing, after consideration of the
+displacement of negative values.
If
.meta sequence
@@ -27067,11 +27073,13 @@ arguments are converted to single range object,
whereas an
.meta index-list
is passed as-is.
-It is an error if a
-.code to
-argument is given, and
+It is an error if the
.code from
-is a list; the situation is diagnosed. If either
+argument is a sequence, indicating an
+.metn index-list ,
+and a
+.code to
+argument is also given; the situation is diagnosed. If either
.code from
or
.code to