From ac38be959685701f4992f4e68e313120c6e82297 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 24 Jan 2017 20:29:00 -0800 Subject: 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. --- lib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib.c') 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))); -- cgit v1.2.3