summaryrefslogtreecommitdiffstats
path: root/lib.c
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
commitac38be959685701f4992f4e68e313120c6e82297 (patch)
tree7da004fef9266891ce069a65b7aa0e9835adad71 /lib.c
parentaf91e7e35cd8277c3a437d9dfddea4c5c313a656 (diff)
downloadtxr-ac38be959685701f4992f4e68e313120c6e82297.tar.gz
txr-ac38be959685701f4992f4e68e313120c6e82297.tar.bz2
txr-ac38be959685701f4992f4e68e313120c6e82297.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.
Diffstat (limited to 'lib.c')
-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)));