summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-01-24 20:29:00 -0800
committerKaz Kylheku <kaz@kylheku.com>2017-01-24 20:29:00 -0800
commit168c1ef04cc7425c0e19ce413b44ca7f4916de5a (patch)
tree7da004fef9266891ce069a65b7aa0e9835adad71
parent542865c4ef2bb7f38398a95f6cbc2ac098002887 (diff)
downloadtxr-168c1ef04cc7425c0e19ce413b44ca7f4916de5a.tar.gz
txr-168c1ef04cc7425c0e19ce413b44ca7f4916de5a.tar.bz2
txr-168c1ef04cc7425c0e19ce413b44ca7f4916de5a.zip
bugfix: take-while, take-until termination condition.
* lib.c (take_while_list_fun, take_until_list_fun): We must terminate the output list when the output list is empty, and not try to apply the predicate to car(list) in that case.
-rw-r--r--lib.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib.c b/lib.c
index ba6318f1..2c4bb209 100644
--- a/lib.c
+++ b/lib.c
@@ -8449,7 +8449,7 @@ static val take_while_list_fun(val env, val lcons)
rplaca(lcons, pop(&list));
- if (!funcall1(pred, funcall1(keyfun, car(list))))
+ if (!list || !funcall1(pred, funcall1(keyfun, car(list))))
rplacd(lcons, nil);
else
rplacd(lcons, make_lazy_cons(lcons_fun(lcons)));
@@ -8493,7 +8493,7 @@ static val take_until_list_fun(val env, val lcons)
rplaca(lcons, item);
- if (funcall1(pred, funcall1(keyfun, item)))
+ if (!list || funcall1(pred, funcall1(keyfun, item)))
rplacd(lcons, nil);
else
rplacd(lcons, make_lazy_cons(lcons_fun(lcons)));