{k1 v11} {k2 v21} …
k1 v11 k2 v22 …
k1 v11 k2 v22 …
k1 v11 k2 v22 …
From: aotto1968 <[email protected]>
Date: Fri May 20 10:13:12 GMT 2022
Subject: proposal: lmap is missing the stride option
"lmap" is a new command to tcl able to filter lists BUT missing the
feature to work an "stride" lists.
a stride list is a list with a pattern of multiple items.
example: The "array get…" produce a flat list of stride of "2"
code: lmap {k v} $packageDEF {list $k [lindex $v 1]}
the code above create a list of lists:
{k1 v11} {k2 v21} …
but I want to have
k1 v11 k2 v22 …
The problem is the "list" command used to return TWO values from
filer-code. The NEW syntax would be:
code: lmap -stride 2 {k v} $packageDEF {list $k [lindex $v 1]}
k1 v11 k2 v22an…
hi,
"lmap" is a new command to tcl able to filter lists BUT missing the
feature to work an "stride" lists.
a stride list is a list with a pattern of multiple items.
example: The "array get…" produce a flat list of stride of "2"
code: lmap {k v} $packageDEF {list $k [lindex $v 1]}
packageDEF is a stride-2 list (k v) with "v" is a list
and I want to filter from "v" the index=1 argument
the code above create a list of lists:
{k1 v11} {k2 v21} …
but I want to have
k1 v11 k2 v22 …
The problem is the "list" command used to return TWO values from
filer-code. The NEW syntax would be:
code: lmap -stride 2 {k v} $packageDEF {list $k [lindex $v 1]}
k1 v11 k2 v22 …
And what would be returned if someone does:
lmap -stride 3 {k v} $packageDEF {list $k [lindex $v 1]}
?
Or even with vayrying list lengths in the "lmap kernel"?
What you're after can be achieved at the moment using:
concat {*}[lmap .... ]
Instead of "-stride" which would be hard to interpret for the case of building a list (as opposed to reading/traversing), I'd much rather see
a "-flatten" switch which does concat the lists instead of appending
into a new list.
Christian
Am 20.05.22 um 18:44 schrieb Christian Gollwitzer:
The problem is the "list" command used to return TWO values from
filer-code. The NEW syntax would be:
code: lmap -stride 2 {k v} $packageDEF {list $k [lindex $v 1]}
k1 v11 k2 v22an…
ah, and for the special case of transforming a key-value list where only
the value is changed, there is "dict map" which does that. Your example
would be:
dict map {k v} $packageDEF {lindex $v 1}
Christian
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 04:40:51 |
| Calls: | 12,099 |
| Calls today: | 7 |
| Files: | 15,003 |
| Messages: | 6,517,897 |