• proposal for lappend -index option

    From aotto1968@21:1/5 to All on Fri May 20 10:17:58 2022
    Hi,

    have a look to the following code. As you see the "insert into a list"
    at the beginning and end have a total different code-style

    OLD:
    ------------------------------------------------------------------------
    switch -regexp -matchvar ARGS $k {

    "^(\w+),package$" {
    set ::SWITCH [linsert $::SWITCH 0 [lindex $ARGS 1] "return $v" ]
    }
    "^pattern2package,(\w+)$" {
    lappend ::SWITCH [lindex $ARGS 1] "return $v"
    }
    }
    ------------------------------------------------------------------------

    with introduction of "lappend ?-index NUM? ..." (default NUM=end) I can
    rewrite the following code

    NEW:
    ------------------------------------------------------------------------
    switch -regexp -matchvar ARGS $k {

    "^(\w+),package$" {
    lappend -index 0 ::SWITCH [lindex $ARGS 1] "return $v"
    }
    "^pattern2package,(\w+)$" {
    lappend ::SWITCH [lindex $ARGS 1] "return $v"
    }
    }
    ------------------------------------------------------------------------

    mfg AO

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Schelte@21:1/5 to All on Fri May 20 11:30:35 2022
    On 20/05/2022 10:17, aotto1968 wrote:
    have a look to the following code. As you see the "insert into a list"
    at the beginning and end have a total different code-style

    OLD:
    ------------------------------------------------------------------------ switch -regexp -matchvar ARGS $k {
      "^(\w+),package$"           {
        set ::SWITCH [linsert $::SWITCH 0 [lindex $ARGS 1] "return $v" ]
      }
      "^pattern2package,(\w+)$"   {
        lappend ::SWITCH [lindex $ARGS 1] "return $v"
      }
    }
    ------------------------------------------------------------------------

    If you want to use similar coding style for inserting at the beginning
    and end, then you can just also use [linsert] to append an element:

    set ::SWITCH [linsert $::SWITCH end [lindex $ARGS 1] "return $v"]


    Schelte.

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