diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-06-06 09:17:40 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-06-06 09:17:40 -0700 |
commit | c27a97c95c628ff1e49339f82537bbf3719ab75a (patch) | |
tree | e918d29f8232608c7a6605bc385cc4eba759a84d /eval.c | |
parent | 6892a6968691e4a5f0965acb83f7e6df202c6007 (diff) | |
download | txr-c27a97c95c628ff1e49339f82537bbf3719ab75a.tar.gz txr-c27a97c95c628ff1e49339f82537bbf3719ab75a.tar.bz2 txr-c27a97c95c628ff1e49339f82537bbf3719ab75a.zip |
Fixing issue with list-like iteration over generic sequences,
namely that empty strings and vectors are not nil.
The nullify function is introduced. It is also exposed to
users, as is the existing make_like function.
* eval.c (mapcarv, mappendv, lazy_mapcar, lazy_mapcarv):
Use nullify to handle non-list inputs correctly.
(eval_init): Registering make_like and nullify as intrinsics.
* lib.c (copy_list, to_seq, list_collect_nconc, list_collect_append,
reverse, lazy_appendv_func, lazy_appendv, ldiff, memq, memql,
memqual, remq, remql, remqual, remove_if, keep_if, rem_lazy_rec,
remq_lazy, remql_lazy, remqual_lazy, remove_if_lazy, keep_if_lazy,
countqual, countql, countq, count_if, some_satisfy, all_satisfy,
none_satisfy, do_chain, chainv, do_and, andv, do_or, orv,
cat_vec, assoc, assql, mapcar, mapcon, mappend, sort, multi_sort,
find, find_if, posqual, posql, posq, pos, pos_if, set_diff,
search): Use nullify for correctness. Some functions fixed
so return sequence matches type of input sequence.
(nullify): New function.
* lib.h (nullify): Declared.
* txr.1: Documented nullify and ake-like.
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -2651,9 +2651,9 @@ static val macroexpand(val form, val menv) val mapcarv(val fun, val list_of_lists) { if (!cdr(list_of_lists)) { - return mapcar(fun, car(list_of_lists)); + return mapcar(fun, nullify(car(list_of_lists))); } else { - val lofl = copy_list(list_of_lists); + val lofl = mapcar(func_n1(nullify), list_of_lists); val list_orig = car(list_of_lists); list_collect_decl (out, otail); @@ -2679,7 +2679,7 @@ static val mappendv(val fun, val list_of_lists) if (!cdr(list_of_lists)) { return mappend(fun, car(list_of_lists)); } else { - val lofl = copy_list(list_of_lists); + val lofl = mapcar(func_n1(nullify), list_of_lists); val list_orig = car(list_of_lists); list_collect_decl (out, otail); @@ -2716,6 +2716,7 @@ static val lazy_mapcar_func(val env, val lcons) val lazy_mapcar(val fun, val list) { + list = nullify(list); if (!list) return nil; return make_lazy_cons(func_f1(cons(fun, list), lazy_mapcar_func)); @@ -2744,7 +2745,7 @@ static val lazy_mapcarv(val fun, val list_of_lists) } else if (some_satisfy(list_of_lists, null_f, identity_f)) { return nil; } else { - val lofl = copy_list(list_of_lists); + val lofl = mapcar(func_n1(nullify), list_of_lists); return make_lazy_cons(func_f1(cons(fun, lofl), lazy_mapcarv_func)); } } @@ -3530,6 +3531,9 @@ void eval_init(void) reg_fun(intern(lit("update"), user_package), func_n2(update)); reg_fun(intern(lit("search"), user_package), func_n4o(search, 2)); + reg_fun(intern(lit("make-like"), user_package), func_n2(make_like)); + reg_fun(intern(lit("nullify"), user_package), func_n1(nullify)); + reg_fun(intern(lit("symbol-value"), user_package), func_n1(symbol_value)); reg_fun(intern(lit("symbol-function"), user_package), func_n1(symbol_function)); reg_fun(intern(lit("boundp"), user_package), func_n1(boundp)); |