diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-04-29 22:37:36 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-04-29 22:37:36 -0700 |
commit | 06d38b335b10d6def68f3f3a340306393fec67fd (patch) | |
tree | 025df04eaaed38116587402466959c00838073fd | |
parent | 853e299c38e5514810574b1094136d64ed375831 (diff) | |
download | txr-06d38b335b10d6def68f3f3a340306393fec67fd.tar.gz txr-06d38b335b10d6def68f3f3a340306393fec67fd.tar.bz2 txr-06d38b335b10d6def68f3f3a340306393fec67fd.zip |
mapcar*: fix broken.
* eval.c (lazy_mapcar_func): We must capture the return value
of iter_step, since we refer to it in the next statement,
expecting it to have stepped. This bug causes a behavior as if
the original list had an extra nil.
* tests/012/lazy.tl: Tests. Poor test coverage is why this
sort of thing comes up and bites us.
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | tests/012/lazy.tl | 6 |
2 files changed, 7 insertions, 1 deletions
@@ -5428,7 +5428,7 @@ static val lazy_mapcar_func(val env, val lcons) us_cons_bind (fun, iter, env); us_rplaca(lcons, funcall1(fun, iter_item(iter))); - us_rplacd(env, iter_step(iter)); + us_rplacd(env, iter = iter_step(iter)); if (iter_more(iter)) us_rplacd(lcons, make_lazy_cons(us_lcons_fun(lcons))); diff --git a/tests/012/lazy.tl b/tests/012/lazy.tl new file mode 100644 index 00000000..be04412a --- /dev/null +++ b/tests/012/lazy.tl @@ -0,0 +1,6 @@ +(load "../common") + +(test [mapcar* list nil] nil) +(test [mapcar* list '(1)] ((1))) +(test [mapcar* list '(1 2 3)] ((1) (2) (3))) +(test [mapcar* list '(1 2 3) '(a b c)] ((1 a) (2 b) (3 c))) |