diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-04-28 20:10:58 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-04-28 20:10:58 -0700 |
commit | 5410fe471273922ee53c579238e3d00bd28b6789 (patch) | |
tree | d0e92ed4314aa2d483b4c0f567ed6859dd239c10 /lib.c | |
parent | 08a31065f8eb9d234cbbaac69d05c7ab7edf22c5 (diff) | |
download | txr-5410fe471273922ee53c579238e3d00bd28b6789.tar.gz txr-5410fe471273922ee53c579238e3d00bd28b6789.tar.bz2 txr-5410fe471273922ee53c579238e3d00bd28b6789.zip |
lib: remove internal use of seq_begin.
The where function is the only place where seq-begin is used
internally. The seq-begin mechanism is marked obsolescent in
the documentation; let's not use it internally.
* lib.c (lazy_where_func, where): Convert to iter_begin.
Also, use us_lcons_fun and us_func_set_env. This seems to be
the only place where lcons_fun and func_set_env are used.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 28 |
1 files changed, 16 insertions, 12 deletions
@@ -11703,24 +11703,28 @@ val contains(val key, val seq, val testfun, val keyfun) return search_common(lit("contains"), 0, seq, key, testfun, keyfun); } -static val lazy_where_func(val seq_iter, val lcons) +static val lazy_where_func(val iter, val lcons) { - struct seq_iter *si = coerce(struct seq_iter *, seq_iter->co.handle); + val iter_orig = iter; us_cons_bind (index, func, lcons); for (;;) { - val item; - if (!si->get(si, &item)) { + if (!iter_more(iter)) { us_rplacd(lcons, nil); return nil; } index = succ(index); - if (funcall1(func, item)) + if (funcall1(func, iter_item(iter))) break; + iter = iter_step(iter); } + iter = iter_step(iter); { - us_rplacd(lcons, make_lazy_cons_car_cdr(lcons_fun(lcons), index, func)); + val fun = us_lcons_fun(lcons); + if (iter != iter_orig) + us_func_set_env(fun, iter); + us_rplacd(lcons, make_lazy_cons_car_cdr(fun, index, func)); return nil; } } @@ -11751,20 +11755,20 @@ static val lazy_where_hash_func(val hash_iter, val lcons) val where(val func, val seq) { if (!hashp(seq)) { - val seq_iter = seq_begin(seq); + val iter = iter_begin(seq); val index = zero; - struct seq_iter *si = coerce(struct seq_iter *, seq_iter->co.handle); for (;;) { - val item; - if (!si->get(si, &item)) + if (!iter_more(iter)) return nil; - if (funcall1(func, item)) + if (funcall1(func, iter_item(iter))) break; + iter = iter_step(iter); index = succ(index); } - return make_lazy_cons_car_cdr(func_f1(seq_iter, lazy_where_func), + iter = iter_step(iter); + return make_lazy_cons_car_cdr(func_f1(iter, lazy_where_func), index, func); } else { val hash_iter = hash_begin(seq); |