• regarding lrange and stride ...

    From Andreas Leitgeb@avl@logic.at to comp.lang.tcl on Mon Jul 1 19:34:54 2024
    From Newsgroup: comp.lang.tcl

    Strided lists are a somewhat common feature in Tcl commands,
    starting with foreach/lmap, lsort, ...

    Recently it occurred to me that [lrange $list $first $last]
    would be extensible to become more helpful for strided lists.

    In essence, an optional 4th argument would be the $stride:

    set list {a A 1 b B 2 c C 3 d D 4}
    lrange $list 1 2 3
    {b B 2 c C 3}

    If not already obvious, the extra stride argument "pretends" that
    there is an extra list level of each 3 elements,
    {{a A 1} {b B 2} {c C 3} {d D 4}} on which the usual lrange
    happens, and then the extra level "disappears".

    In the simple "numeric" cases it would be essentially like:
    proc lrange_s {l f t s} {
    lrange $l [expr {$f*$s}] [expr {($t+1)*$s-1}]
    }
    ...plus extra code for nonnumeric indices "end", "end-42", "40+2",...
    and some special cases where [llength $list] is not an integral multiple
    of the stride.

    --- Synchronet 3.20a-Linux NewsLink 1.114