summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib.c43
-rw-r--r--tests/012/iter.tl4
-rw-r--r--txr.134
3 files changed, 36 insertions, 45 deletions
diff --git a/lib.c b/lib.c
index a1235247..c7bf5b05 100644
--- a/lib.c
+++ b/lib.c
@@ -590,8 +590,14 @@ static int seq_iter_get_range_str(seq_iter_t *it, val *pval)
*pval = it->ui.vn;
for (; l > 0; l--) {
- if (++nx[l - 1] <= bn[l - 1])
- break;
+ if (in[l - 1] < bn[l - 1]) {
+ if (++nx[l - 1] <= bn[l - 1])
+ break;
+ } else {
+ if (--nx[l - 1] >= bn[l - 1])
+ break;
+ }
+
nx[l - 1] = in[l - 1];
}
@@ -666,33 +672,6 @@ static int seq_iter_peek_rev_range_number(seq_iter_t *it, val *pval)
return 0;
}
-static int seq_iter_get_rev_range_str(seq_iter_t *it, val *pval)
-{
- if (it->ui.vn) {
- val init = from(it->inf.obj);
- val len = length_str(init);
- val next = copy_str(it->ui.vn);
- cnum l = c_num(len, nil);
- wchar_t *nx = strip_qual(wchar_t *, c_str(next, nil));
- const wchar_t *in = c_str(init, nil);
- const wchar_t *bn = c_str(it->ul.vbound, nil);
-
- *pval = it->ui.vn;
-
- for (; l > 0; l--) {
- if (--nx[l - 1] >= bn[l - 1])
- break;
- nx[l - 1] = in[l - 1];
- }
-
- it->ui.vn = if2(l > 0, next);
-
- return 1;
- }
-
- return 0;
-}
-
static int seq_iter_get_chr(seq_iter_t *it, val *pval)
{
if (it->ui.index <= 0x10FFFF) {
@@ -1000,10 +979,6 @@ struct seq_iter_ops si_rev_range_number_ops =
seq_iter_ops_init(seq_iter_get_rev_range_number,
seq_iter_peek_rev_range_number);
-struct seq_iter_ops si_rev_range_str_ops =
- seq_iter_ops_init(seq_iter_get_rev_range_str,
- seq_iter_peek_range_str);
-
struct seq_iter_ops si_chr_ops = seq_iter_ops_init_nomark(seq_iter_get_chr,
seq_iter_peek_chr);
@@ -1133,7 +1108,7 @@ void seq_iter_init_with_info(val self, seq_iter_t *it,
case LSTR:
it->ui.vn = copy_str(rf);
it->ul.vbound = rt;
- it->ops = &si_rev_range_str_ops;
+ it->ops = &si_range_str_ops;
if (eql(length_str(rf), length_str(rt)))
break;
/* fallthrough */
diff --git a/tests/012/iter.tl b/tests/012/iter.tl
index 0823849e..96bcabbd 100644
--- a/tests/012/iter.tl
+++ b/tests/012/iter.tl
@@ -58,6 +58,10 @@
"F06" "F07" "F08" "F09" "F10"))
(test
+ (list-seq "AC".."CA")
+ ("AC" "AB" "AA" "BC" "BB" "BA" "CC" "CB" "CA"))
+
+(test
[mapcar identity [3..6 0..10]] (3 4 5))
;; iterating from fixnum to bignum was rejected in up to txr-269.
diff --git a/txr.1 b/txr.1
index 8562eabb..0135c79c 100644
--- a/txr.1
+++ b/txr.1
@@ -39690,20 +39690,17 @@ and
steps through the same values in reverse order.
A string range consists of two strings of equal length. If the strings are
-of unequal length, an error exception is thrown. For the range to operate
-as intended, the strings must meet some additional requirements. If the
-.code from
-string is lexicographically lesser than the
-.code to
-string, as determined by the
-.code less
-function, then the range is ascending, otherwise it is descending. The string
-range iterates by incrementing (or decrementing, in the case of a descending range)
-the characters of the
+of unequal length, an error exception is thrown.
+The sequence denoted by a string range is a sequence of strings formed
+from the the Cartesian product of the character ranges formed by
+positionally-corresponding characters from the two strings.
+The order of the sequence is such that the rightmost character varies most
+frequently. In more detail, the string range iterates over successive strings
+by incrementing or decrementing the characters of the
.code from
string until they are equal to those of the
.code to
-string. The last character has priority. For instance, the range
+string. The rightmost character has priority. For instance, the range
.code "\(dqAA\(dq..\(dqCC\(dq"
iterates over the strings
.codn "AA" ,
@@ -39724,6 +39721,21 @@ character attains the value of the corresponding character in the
string, that character is reset to its starting value, and its left neighbor,
if it exists, is incremented instead. If no left neighbor exists, the
iteration terminates.
+For every character position in the string pair, it is independently
+determined whether the iteration for that position is ascending or descending,
+such that the range
+.code "\(dqAC\(dq..\(dqCA\(dq"
+iterates over the strings
+.codn "AC" ,
+.codn "AB" ,
+.codn "AA" ,
+.codn "BC" ,
+.codn "BB" ,
+.codn "BA" ,
+.codn "CC" ,
+.code "CB"
+and
+.codn "CA" .
Search trees are iterable. Iteration entails an in-order visits of the elements
of a tree. A tree iterator created by