regarding lrange and stride ...

Liste des GroupesRevenir à cl tcl 
Sujet : regarding lrange and stride ...
De : avl (at) *nospam* logic.at (Andreas Leitgeb)
Groupes : comp.lang.tcl
Date : 01. Jul 2024, 20:34:54
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <slrnv8616u.3gvbf.avl@logic.at>
User-Agent : slrn/1.0.3 (Linux)
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.


Date Sujet#  Auteur
1 Jul 24 o regarding lrange and stride ...1Andreas Leitgeb

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal