summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-06-06 20:40:20 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-06-06 20:40:20 -0700
commit265746e8cfedd7efed194f968500c041b2af20af (patch)
tree33c60d47fb74f5995cc187918e7dee2e8ddfb79f
parent16397fbdedaa4510bf17b4a27cb67ecb1ee0a3c2 (diff)
downloadtxr-265746e8cfedd7efed194f968500c041b2af20af.tar.gz
txr-265746e8cfedd7efed194f968500c041b2af20af.tar.bz2
txr-265746e8cfedd7efed194f968500c041b2af20af.zip
Handle sequence better in index list case of replace.
* lib.c (replace_list): Simplify treatment of items on entry using toseq. (replace_str, replace_vec): When a list or vector of indices is given, use the itseq result of passing items items through toseq function rather than original items, for consistency with range assignment.
-rw-r--r--lib.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/lib.c b/lib.c
index c734324b..3e245e40 100644
--- a/lib.c
+++ b/lib.c
@@ -1136,12 +1136,7 @@ val replace_list(val list, val items, val from, val to)
{
val len = nil;
- if (vectorp(items))
- items = list_vec(items);
- else if (stringp(items))
- items = list_str(items);
- else if (!listp(items))
- uw_throwf(error_s, lit("replace-list: cannot replace with ~s"), items, nao);
+ items = toseq(items);
if (!list)
return items;
@@ -3497,11 +3492,11 @@ val replace_str(val str_in, val items, val from, val to)
lit("replace-str: to-arg not applicable when from-arg is a list"),
nao);
- for (; where && items; where = cdr(where)) {
+ for (; where && itseq; where = cdr(where)) {
val wh = car(where);
if (ge(wh, len))
break;
- chr_str_set(str_in, wh, pop(&items));
+ chr_str_set(str_in, wh, pop(&itseq));
}
return str_in;
@@ -3516,11 +3511,11 @@ val replace_str(val str_in, val items, val from, val to)
lit("replace-str: to-arg not applicable when from-arg is a vector"),
nao);
- for (i = zero; lt(i, wlen) && items; i = plus(i, one)) {
+ for (i = zero; lt(i, wlen) && itseq; i = plus(i, one)) {
val wh = vecref(where, i);
if (ge(wh, len))
break;
- chr_str_set(str_in, wh, pop(&items));
+ chr_str_set(str_in, wh, pop(&itseq));
}
return str_in;
@@ -6226,11 +6221,11 @@ val replace_vec(val vec_in, val items, val from, val to)
lit("replace-vec: to-arg not applicable when from-arg is a list"),
nao);
- for (; where && items; where = cdr(where)) {
+ for (; where && it_seq; where = cdr(where)) {
val wh = car(where);
if (ge(wh, len))
break;
- set(vecref_l(vec_in, wh), pop(&items));
+ set(vecref_l(vec_in, wh), pop(&it_seq));
}
return vec_in;
@@ -6245,11 +6240,11 @@ val replace_vec(val vec_in, val items, val from, val to)
lit("replace-vec: to-arg not applicable when from-arg is a vector"),
nao);
- for (i = zero; lt(i, wlen) && items; i = plus(i, one)) {
+ for (i = zero; lt(i, wlen) && it_seq; i = plus(i, one)) {
val wh = vecref(where, i);
if (ge(wh, len))
break;
- set(vecref_l(vec_in, wh), pop(&items));
+ set(vecref_l(vec_in, wh), pop(&it_seq));
}
return vec_in;