summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-08-14 19:50:55 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-08-14 19:50:55 -0700
commitd5e10dc54a6b128b682a37f7caf7a8dffcc4b705 (patch)
treea8f68c065c8d5e838e7be4bb3e1a2726a402eec0
parenteef130239922e5309a23c0ea5c3ba327026be8ff (diff)
downloadtxr-d5e10dc54a6b128b682a37f7caf7a8dffcc4b705.tar.gz
txr-d5e10dc54a6b128b682a37f7caf7a8dffcc4b705.tar.bz2
txr-d5e10dc54a6b128b682a37f7caf7a8dffcc4b705.zip
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.
-rw-r--r--lib.c20
1 files 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;