• proposal: lmap is missing the stride option

    From aotto1968@21:1/5 to All on Fri May 20 12:13:12 2022
    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 …

    mfg AO

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From aotto1968@21:1/5 to All on Fri May 20 12:15:37 2022
    On 20.05.22 12:13, aotto1968 wrote:
    k1 v11 k2 v22 …

    correct: I want to have: > k1 v11 k2 v21!! …

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From clt.to.davebr@dfgh.net@21:1/5 to All on Fri May 20 14:35:19 2022
    From: aotto1968 <aotto1968@t-online.de>
    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 …

    [concat {*}[lmap {k v} $packageDEF {list $k [lindex $v 1]}]

    will get the result you want.

    I end up using this a lot, and would like a cleaner way to have the script argument to lmap generate multiple items in the lmap result.

    However I do not think -stride is the proper name for this option, and do not see why a number of items is necessary or even useful. Why not just append as many items as appear in the script result treated as a list?

    Perhaps adding a option (-concat ?) to lmap which concatenates the result of the script to the [lmap] result. Something like:

    lmap -concat {k v} $packageDEF {list $k [lindex $v 1]}


    Dave B

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Christian Gollwitzer@21:1/5 to All on Fri May 20 18:47:50 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Christian Gollwitzer@21:1/5 to All on Fri May 20 18:44:46 2022
    Am 20.05.22 um 12:13 schrieb aotto1968:
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From aotto1968@21:1/5 to Christian Gollwitzer on Sat May 21 13:40:10 2022
    On 20.05.22 18:44, Christian Gollwitzer wrote:
    ~~

    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

    I thing the -stride 3 is not a problem because returning a
    list-of-length-3 from the filter is an easy condition to test. If this condition is NOT ok than raise an error.

    mfg.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From aotto1968@21:1/5 to Christian Gollwitzer on Sat May 21 13:42:52 2022
    On 20.05.22 18:47, Christian Gollwitzer wrote:
    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

    ok, for stride-2 this is a possible solution but how expensive it is to
    build a dict?

    performance | dict : list → dict → filter → dict → list
    performance | -stride 2 : list → filter → list


    mfg AO

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)