diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-08-22 11:19:35 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-08-22 11:19:35 -0700 |
commit | 1819c8bea0d960f2895485e58901dbcc6193d071 (patch) | |
tree | a328d7167e976ae88f8985b2685d7a0a1592d0fd /txr.1 | |
parent | 9ec47b693f9618bfd29347226157dc2f8a655ff8 (diff) | |
download | txr-1819c8bea0d960f2895485e58901dbcc6193d071.tar.gz txr-1819c8bea0d960f2895485e58901dbcc6193d071.tar.bz2 txr-1819c8bea0d960f2895485e58901dbcc6193d071.zip |
sub: allow generic iterables.
In this patch we allow the s in (sub s from to) and [s from..to]
to be any iterable.
* lib.c (iter_dynamic, sub_iter): New static function.
(generic_funcall): Handle all objects via the sequence case:
ref, sub and all that. Unfortunately, we lose some error
handling at the level of the sub function. But we allow any
iterable to be passed through to sub.
(sub): Handle default case through sub_iter.
* tests/012/iter.tl: New cases.
* txr.1: Documented.
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -15533,6 +15533,15 @@ is a list, then the .meta sequence form itself must be a place. +This form is implemented using the +.code ref +accessor such that, except for the argument evaluation semantics of the DWIM +brackets, it is equivalent to using the +.mono +.meti (ref < sequence << index ) +.onom +syntax. + .meIP >> [ sequence << from-index..to-below-index ] Retrieve the specified range of elements. The range of elements is specified in the @@ -15564,6 +15573,19 @@ regardless of whether the target is a string, vector or list. If the target is a string, the replacement sequence must be a string, or a list or vector of characters. +The semantics is implemented using the +.code sub +accessor, such that the following equivalence holds: + +.verb + [seq from..to] <--> (sub seq from..to) +.brev + +For this reason, +.meta sequence +may be any object that is iterable by +.codn iter-begin . + .meIP >> [ sequence << index-list ] Elements specified by @@ -31512,6 +31534,23 @@ is not an accessor, assigning to the .code sub syntax in this case will produce an error. +The +.meta sequence +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 +.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 +.code sub +is returned. + If .meta sequence is a structure, it must support the |