diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-02-27 20:13:01 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-02-27 20:13:01 -0800 |
commit | ee9fb41197c8a948144b9f384da273688bdd538c (patch) | |
tree | cfaa9cf87db76490574aaaa23b3481e17dce99af /lib.c | |
parent | fb09dfc8559a5b01c75b691613cf9eda54f7bee5 (diff) | |
download | txr-ee9fb41197c8a948144b9f384da273688bdd538c.tar.gz txr-ee9fb41197c8a948144b9f384da273688bdd538c.tar.bz2 txr-ee9fb41197c8a948144b9f384da273688bdd538c.zip |
mapcar, mappend: switch to seq_build.
* lib.c (mapcar): Implement with seq_iter and seq_build,
rather than relying on mapcar_listout and make_like.
(mappend): Replace list_collect_decl and make_like
with seq_build.
* eval.c (map_common): Replace list_collect_decl and
make_like with seq_build. The collect_fn is now a pointer
to either seq_add or seq_pend rather than list_collect
or list_collect_append.
(mapcarv, mappendv): Pass seq_add and seq_pend to
map_common, rather than list_collect and list_collect_append.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -10889,7 +10889,18 @@ val mapcar_listout(val fun, val seq) val mapcar(val fun, val seq) { - return make_like(mapcar_listout(fun, seq), seq); + val self = lit("mapcar"); + seq_iter_t iter; + seq_build_t build; + val elem; + + seq_iter_init(self, &iter, seq); + seq_build_init(self, &build, seq); + + while (seq_get(&iter, &elem)) + seq_add(&build, funcall1(fun, elem)); + + return seq_finish(&build); } val mapcon(val fun, val list) @@ -10909,15 +10920,16 @@ val mappend(val fun, val seq) { val self = lit("mappend"); seq_iter_t iter; + seq_build_t build; val elem; - list_collect_decl (out, ptail); seq_iter_init(self, &iter, seq); + seq_build_init(self, &build, seq); while (seq_get(&iter, &elem)) - ptail = list_collect_append(ptail, funcall1(fun, elem)); + seq_pend(&build, funcall1(fun, elem)); - return make_like(out, seq); + return seq_finish(&build); } val mapdo(val fun, val seq) |