我想运行 lmap,但是是破坏性的,即在 elist 本身上。我当然可以用
set listy [ lmap x $listy { func1 x } ]
没有内置命令。你需要做一些循环:
set items {q w e r t y u i o p}
# iterate over the indices
for {set idx 0} {$idx < [llength $items]} {incr idx} {
# get the item
set item [lindex $items $idx]
# generate an updated item
set item [string toupper $item]
# put the updated item back
lset items $idx $item
}
puts $items
请注意,值是概念上写时复制(尽管幕后实现比这更有效);在运行循环之前拥有该列表的任何内容都不会看到更新,除非它们重新读取包含该列表的变量。这在实践中比在脚下改变值更好(更低的错误率)......