Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You will always get the greatest recognition for the job you least like.


comp / comp.lang.tcl / regarding lrange and stride ...

SubjectAuthor
o regarding lrange and stride ...Andreas Leitgeb

1
Subject: regarding lrange and stride ...
From: Andreas Leitgeb
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Mon, 1 Jul 2024 19:34 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: avl@logic.at (Andreas Leitgeb)
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=
View all headers

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.

1

rocksolid light 0.9.8
clearnet tor