From dc7842296466eba508f791ef1f9a9c3b16f7d4da Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 28 Jun 2019 07:17:12 -0700 Subject: seq-begin: bugfix: non-lists don't work. * lib.c (seq_begin): Do not null out si->inf.obj; it's needed for accessing hashes and vector-like objects. This bug means that seq-begin iteration has only worked correctly for lists. The original motivation was not to have spurious retention of the head of a lazy list, which is hereby reintroduced. But iterators can be rewound. Let's just document this away and leave it as a to-do item. * txr.1: Document the limitation of seq-begin w.r.t. lazy lists. --- lib.c | 1 - txr.1 | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib.c b/lib.c index 40662d29..522128a6 100644 --- a/lib.c +++ b/lib.c @@ -454,7 +454,6 @@ val seq_begin(val obj) struct seq_iter *si = coerce(struct seq_iter *, chk_calloc(1, sizeof *si)); si_obj = cobj(coerce(mem_t *, si), seq_iter_s, &seq_iter_ops); seq_iter_init(self, si, obj); - si->inf.obj = nil; return si_obj; } diff --git a/txr.1 b/txr.1 index 689715e3..5377e3b4 100644 --- a/txr.1 +++ b/txr.1 @@ -31952,6 +31952,14 @@ If .meta object isn't a sequence, an exception is thrown. +Note that if +.meta object +is a lazy list, the returned iterator maintains a reference to the +head of that list during the traversal; therefore, generic iteration +based on iterators from +.code seq-begin +is not suitable for indefinite iteration over infinite lists. + .coNP Function @ seq-next .synb .mets (seq-next < iter << end-value ) -- cgit v1.2.3