diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-12-20 19:32:36 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-12-20 19:32:36 -0800 |
commit | f0a538af2282cd9425c547b151779c982a3ebc03 (patch) | |
tree | a782a63e5c7f63d6347e717d117939f2d97e28a8 | |
parent | 6d51949c4820f8eeebd6aacfb443c11b2465f6ab (diff) | |
download | txr-f0a538af2282cd9425c547b151779c982a3ebc03.tar.gz txr-f0a538af2282cd9425c547b151779c982a3ebc03.tar.bz2 txr-f0a538af2282cd9425c547b151779c982a3ebc03.zip |
maprodo: bugfix: spurious return value.
There are cases when maprodo returns a non-nil value, even
though it is supposed to collect nothing. This is because
though it is is collecting nothing, that nothing is sometimes
converted to an alternative return type via make_like.
* eval.c (prod_common): We allow the collect_fn function
pointer to be null, to indicate nothing is to be collected,
rather than using a stub. If collect_fn is null, we just call
the mapping function without collecting its value, and at the
end, we do not involve make_like and just return nil.
(collect_nothing): Static function removed.
(maprodo): Pass null function pointer instead of collect_nothing.
-rw-r--r-- | eval.c | 16 |
1 files changed, 7 insertions, 9 deletions
@@ -5725,6 +5725,7 @@ static val prod_common(val self, val fun, struct args *lists, goto out; for (;;) { + val ret; for (i = 0; i < argc; i++) args_fun->arg[i] = iter_item(args_work->arg[i]); @@ -5732,7 +5733,10 @@ static val prod_common(val self, val fun, struct args *lists, args_fun->fill = argc; args_fun->list = 0; - ptail = collect_fn(ptail, generic_funcall(fun, args_fun)); + ret = generic_funcall(fun, args_fun); + + if (collect_fn) + ptail = collect_fn(ptail, ret); for (i = argc - 1; ; i--) { val step_i = iter_step(args_work->arg[i]); @@ -5746,7 +5750,7 @@ static val prod_common(val self, val fun, struct args *lists, } } out: - return make_like(out, args_at(lists, 0)); + return collect_fn ? make_like(out, args_at(lists, 0)) : nil; } } @@ -5760,15 +5764,9 @@ val maprendv(val fun, struct args *lists) return prod_common(lit("maprend"), fun, lists, list_collect_append, mappendv); } -static loc collect_nothing(loc ptail, val obj) -{ - (void) obj; - return ptail; -} - static val maprodo(val fun, struct args *lists) { - return prod_common(lit("maprodo"), fun, lists, collect_nothing, mapdov); + return prod_common(lit("maprodo"), fun, lists, 0, mapdov); } static val symbol_value(val sym) |