From 70ee17726d2c419c049ad87098e61a73bcd14766 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 14 Aug 2019 19:50:55 -0700 Subject: where: bugfix: doesn't work for non-list sequence. * lib.c (lazy_where_func, where): We have a regression here due to strangely trying to smuggle the predicate function in si->inf.obj, which cannot possibly work other than for lists whose seq iterators ignore that field. We switch to the trick of using the cdr field of the lazy cons to carry that forward. --- lib.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/lib.c b/lib.c index 932a3f07..721f68a0 100644 --- a/lib.c +++ b/lib.c @@ -10459,22 +10459,21 @@ val rsearch(val seq, val key, val testfun, val keyfun) static val lazy_where_func(val seq_iter, val lcons) { struct seq_iter *si = coerce(struct seq_iter *, seq_iter->co.handle); - val index = succ(us_car(lcons)); - val func = si->inf.obj; + us_cons_bind (index, func, lcons); for (;;) { val item; if (!si->get(si, &item)) { - si->inf.obj = nil; + us_rplacd(lcons, nil); return nil; } + index = succ(index); if (funcall1(func, item)) break; - index = succ(index); } { - us_rplacd(lcons, make_lazy_cons_car(lcons_fun(lcons), index)); + us_rplacd(lcons, make_lazy_cons_car_cdr(lcons_fun(lcons), index, func)); return nil; } } @@ -10511,20 +10510,15 @@ val where(val func, val seq) for (;;) { val item; - if (!si->get(si, &item)) { - si->inf.obj = nil; + if (!si->get(si, &item)) return nil; - } if (funcall1(func, item)) break; index = succ(index); } - { - val cell = make_lazy_cons_car(func_f1(seq_iter, lazy_where_func), index); - si->inf.obj = func; - return cell; - } + return make_lazy_cons_car_cdr(func_f1(seq_iter, lazy_where_func), + index, func); } else { val hash_iter = hash_begin(seq); val key; -- cgit v1.2.3