From bc67f81929e9384b347e62fe35e005e75e92981b Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 7 Jul 2024 21:15:41 -0700 Subject: sub: don't produce an iterator. Having the sub function yield an iterator in some cases is a defective requirement, causing problems like this: 1> (partition 1..10 '(2 3)) ((1 2) (3) #) With fix: 1> (partition 1..10 '(2 3)) ((1 2) (3) (4 5 6 7 8 9)) * lib.c (sub_iter): When the interval is open and we are operating on a sequence via iter-begin, do not return an iterator. Convert it to a lazy list. Not subjecting this to -C compat flag; I can't imagine anyone writing code to depend on this, rather than stepping around it as a bugx. * txr.1: Documentation updated. --- lib.c | 2 +- txr.1 | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib.c b/lib.c index 8418844a..52f984e3 100644 --- a/lib.c +++ b/lib.c @@ -3014,7 +3014,7 @@ static val sub_iter(val obj, val from, val to) if (!to) { do { if (ge(idx, from)) - return iter_dynamic(&iter); + return list_seq(iter_dynamic(&iter)); idx = succ(idx); } while (seq_get(&iter, &elem)); } else { diff --git a/txr.1 b/txr.1 index bda03dcc..c18ee4ce 100644 --- a/txr.1 +++ b/txr.1 @@ -34701,14 +34701,14 @@ argument may also be any other object type that is suitable as input to the .code iter-begin function. In this situation, assigning to .code sub -syntax produces an error. The behavior is complex. In cases where the +syntax produces an error. Furthermore, in cases where the .meta from and .meta to arguments imply that a suffix of .meta sequence -is required, an iterator may be returned which traverses the suffix -of the sequence. In other cases, a list of the elements selected by +is required, an lazy list of the suffix of the iterated sequence +will be returned. In other cases, a regular list of the elements selected by .code sub is returned. -- cgit v1.2.3