1 2 3
1 2 3
{1 2 3}
request new command lstride (ref: https://wiki.tcl-lang.org/page/request+new+command+lstride)
The following code is used:
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
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

lappend a {*}[list 1 2 3]
1 2 3
lappend b [lstride 1 2 3]
1 2 3
On 17.05.24 19:14, Christian Gollwitzer wrote:
Am 17.05.24 um 11:52 schrieb aotto1968:
OK
more easy example

lappend a {*}[list 1 2 3]
1 2 3
lappend b [lstride 1 2 3]
1 2 3
impossible. This would violate the basic rules of Tcl
I don't understand the problem of tcl the "Tcl_Obj" just need an
*flat-flag* and
if you build the argument-list of a function-call you check this flag.
I don't even require that the *flat-flag* is persistent (convert to
string and back)
Am 17.05.24 um 11:52 schrieb aotto1968:
OK
more easy example

lappend a {*}[list 1 2 3]
1 2 3
lappend b [lstride 1 2 3]
1 2 3
impossible. This would violate the basic rules of Tcl
Christian
{{*}1 2 3}
request new command lstride (ref: https://wiki.tcl-lang.org/page/request+new+command+lstride)current:
array set attributeDEF \suggestion:
[concat {*}[lmap {k v} [array get attributeDEF $old,*] {list [string map $mapL $k] $v} ]]
array set attributeDEF [lmap {k v} [array get attributeDEF $old,*] {lstride [string map $mapL $k] $v} ]
aotto1968 <[email protected]> wrote:
request new command lstride (ref: https://wiki.tcl-lang.org/page/request+new+command+lstride)current:
array set attributeDEF \suggestion:
[concat {*}[lmap {k v} [array get attributeDEF $old,*] {list [string map $mapL $k] $v} ]]
array set attributeDEF [lmap {k v} [array get attributeDEF $old,*] {lstride [string map $mapL $k] $v} ]
Ignoring the further thread as it went straightforward against the
spirit of Tcl, there would still be a different (and tcl-conform)
way to achieve that:
The focus would need to go to lmap: it could interpret a specific return-code (aside from "break" and "continue") - lets take 42 just
for now - and handle it such, that the value returned from
the lmap body is treated as a list and concated to the accumulator.
lmap -join {k v} [array get attributeDEF $old,*] {list [string map $mapL $k] $v} ]]
Am 18.05.24 um 16:04 schrieb Andreas Leitgeb:
aotto1968 <[email protected]> wrote:I agree that changing lmap would be the way to go forward here -
request new command lstride (ref: https://wiki.tcl-lang.org/page/request+new+command+lstride)current:
array set attributeDEF \suggestion:
[concat {*}[lmap {k v} [array get attributeDEF $old,*] {list [string map $mapL $k] $v} ]]
array set attributeDEF [lmap {k v} [array get attributeDEF $old,*] {lstride [string map $mapL $k] $v} ]The focus would need to go to lmap: it could interpret a specific
return-code (aside from "break" and "continue") - lets take 42 just
for now - and handle it such, that the value returned from
the lmap body is treated as a list and concated to the accumulator.
however, the whole lstride thing seems overcomplicated to me. How about
an additional option for lmap, say, "-flat" or "-join" that makes lmap
concat the results instead of lappending?
lmap -join {k v} [array get attributeDEF $old,*] {list [string map $mapL $k] $v} ]]Christian
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 04:38:55 |
| Calls: | 12,099 |
| Calls today: | 7 |
| Files: | 15,003 |
| Messages: | 6,517,897 |