request new command lstride

Difference between version 2 and 3 - Previous - Next
The following code is used:

======tcl
proc lib_ME__copy_what {whatRef old new} {
  upvar $whatRef whatDEF
  global attributeDEF ARG_TYPE_ATTRIBUTE RET_TYPE_ATTRIBUTE ARG_DEFAULT

  set mapL  [list $old $new]

  array set attributeDEF \
    [concat {*}[lmap {k v} [array get attributeDEF $old,*]        {list [string map $mapL $k] $v} ]]
  array set ARG_TYPE_ATTRIBUTE \
    [concat {*}[lmap {k v} [array get ARG_TYPE_ATTRIBUTE $old,*]  {list [string map $mapL $k] $v} ]]
  array set RET_TYPE_ATTRIBUTE \
    [concat {*}[lmap {k v} [array get RET_TYPE_ATTRIBUTE $old,*]  {list [string map $mapL $k] $v} ]]
  array set ARG_DEFAULT \
    [concat {*}[lmap {k v} [array get ARG_DEFAULT $old,*]         {list [string map $mapL $k] $v} ]]
  set whatDEF($new) $whatDEF($old)
}
======

the syntax I recommend is

======tcl
proc lib_ME__copy_what {whatRef old new} {
  upvar $whatRef whatDEF
  global attributeDEF ARG_TYPE_ATTRIBUTE RET_TYPE_ATTRIBUTE ARG_DEFAULT

  set mapL  [list $old $new]

  array set attributeDEF       [lmap {k v} [array get attributeDEF $old,*]        {lstride [string map $mapL $k] $v} ]
  array set ARG_TYPE_ATTRIBUTE [lmap {k v} [array get ARG_TYPE_ATTRIBUTE $old,*]  {lstride [string map $mapL $k] $v} ]
  array set RET_TYPE_ATTRIBUTE [lmap {k v} [array get RET_TYPE_ATTRIBUTE $old,*]  {lstride [string map $mapL $k] $v} ]
  array set ARG_DEFAULT        [lmap {k v} [array get ARG_DEFAULT $old,*]         {lstride [string map $mapL $k] $v} ]
  set whatDEF($new) $whatDEF($old)
}
======

The new command `lstride` has the same effect as `{*}` this mean create a '''flat''' list

more easy example

======tcl
lappend x 1 2 3
=> 1 2 3

lappend a {*}[list 1 2 3]
=> 1 2 3

lappend b [lstride 1 2 3]
=> 1 2 3

lappend c [list 1 2 3]
=> {1 2 3}
======----
'''[arjen] - 2024-05-17 11:28:46'''

The operation {*} does not create a flat list, but instead splits up the list in separate elements:

% set a {*}[list 1 2 3] 
wrong # args: should be "set varName ?newValue?"

results in an error, because the set command would get four arguments in stead of two.

Also, "stride" is usually concerned with stepping through a list with a certain step size. So in my opinion the name is misleading. I thought  you were proposing a command to make a subselection of a list like:

% lstride [list 1 2 3 4 5 6] 2
1 3 5

(and possibly more options ;))