Deutsch   English   Français   Italiano  
<slrnv8616u.3gvbf.avl@logic.at>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!2.eu.feeder.erje.net!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Andreas Leitgeb <avl@logic.at>
Newsgroups: comp.lang.tcl
Subject: regarding lrange and stride ...
Date: Mon, 1 Jul 2024 19:34:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <slrnv8616u.3gvbf.avl@logic.at>
Reply-To: avl@logic.at
Injection-Date: Mon, 01 Jul 2024 21:34:54 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="4b99c451c4a1716499a82b7ed609deaa";
	logging-data="1293483"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/Ncyt+Odum256OwjAkAvEw"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:qUHyvLTzebfjEDJm2aS+6fm/Plw=
Bytes: 1745

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.