From f91a1c23bc13b93b9e084173b2377d6124c6469a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 6 Jun 2016 20:40:20 -0700 Subject: 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. --- lib.c | 23 +++++++++-------------- 1 file 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; -- cgit v1.2.3