From 9fa70b67bad4f95c22fa0e7a1148b88c82f375e1 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 22 Jan 2014 23:39:45 -0800 Subject: Changes to the list collection mechanism to improve the extension of list operations over vectors and strings. * eval.c (do_eval_args, bindings_helper, op_each, subst_vars, supplement_op_syms, mapcarv, mappendv): Switch from list_collect_* macros to functions. * lib.c (copy_list): Switch from list_collect* macros to functions. Use list_collect_nconc for the final terminator. Doing a copy there with list_collect_append was actually wasteful, and now that list_collect_append calls copy_list in places, it triggered runaway recursion. (make_like): Bugfix: list_vector was used instead of vector_list. (to_seq, list_collect, list_collect_nconc, list_collect_append): New functions. (append2, appendv, nappend2, sub_list, replace_list, ldiff, remq, remql, remqual, remove_if, keep_if, proper_plist_to_alist, improper_plist_to_alist, split_str, split_str_set, tok_str, list_str, chain, andf, orf, lis_vector, mapcar, mapcon, mappend, merge, set_diff, env): Switch from list_collect* macros to functions. (replace_str, replace_vec): Allow single item replacement sequence. * lib.h (to_seq): Declared. (list_collect, list_collect_nconc, list_collect_append): Macros removed, replaced by function declarations of the same name. These functions return the new ptail since they cannot assign to it, requiring all uses to be updated to do the assignment of the returned value. (list_collect_decl): Use val rather than obj_t *. * match.c (vars_to_bindings, h_coll, subst_vars, extract_vars, extract_bindings, do_output_line, do_output, v_gather, v_collect): Switch from list_collect* macros to functions. * parser.y (o_elems_transform): Likewise. * regex.c (dv_compile_regex, regsub): Likewise. * txr.c (txr_main): Likewise. --- regex.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'regex.c') diff --git a/regex.c b/regex.c index 765112ce..06e19cd2 100644 --- a/regex.c +++ b/regex.c @@ -1306,9 +1306,9 @@ static val dv_compile_regex(val exp) return cobj((mem_t *) set, chset_s, &char_set_obj_ops); } else if (sym == compound_s) { list_collect_decl (out, iter); - list_collect (iter, compound_s); + iter = list_collect(iter, compound_s); for (; args; args = cdr(args)) - list_collect (iter, dv_compile_regex(first(args))); + iter = list_collect(iter, dv_compile_regex(first(args))); return out; } else if (sym == zeroplus_s || sym == oneplus_s || sym == optional_s || sym == compl_s) { @@ -1865,16 +1865,17 @@ val regsub(val regex, val repl, val str) if (!find) { if (pos == zero) return str; - list_collect(ptail, sub_str(str, pos, nil)); + ptail = list_collect(ptail, sub_str(str, pos, nil)); break; } - list_collect(ptail, sub_str(str, pos, find)); - list_collect(ptail, if3(isfunc, - funcall1(repl, sub_str(str, find, plus(find, len))), - repl)); + ptail = list_collect(ptail, sub_str(str, pos, find)); + ptail = list_collect(ptail, if3(isfunc, + funcall1(repl, sub_str(str, find, + plus(find, len))), + repl)); if (len == zero && eql(find, pos)) { if (lt(pos, length_str(str))) { - list_collect(ptail, chr_str(str, pos)); + ptail = list_collect(ptail, chr_str(str, pos)); pos = plus(pos, one); } } else { -- cgit v1.2.3