我在父函数中有一个嵌套列表,我想在其中一个被调用函数中附加一些元素
proc myparent {
set mylist {}
foreach elem $listelements {
lappend mylist $elem
}
#at this point, mylist looks something like this:
# { {var1 val1} {var2 val2} {var3 val3} }
myproc1 mylist #--> want to append mylist here
#myproc1 is expected to add another sublist to mylist. mylist after myproc1 should look like this:
# { {var1 val1} {var2 val2} {var3 val3} {abc def} }
myproc2 $mylist #--> need to use the updated mylist here
}
在 myproc1 中,我想将一些元素附加到 mylist。我尝试了以下方法:
myproc1 { {list_var -list} } {
upvar $list_var list_local
#some conditional logic
lappend list_local [list "abc" "def"]
}
但它没有按预期工作。upvar 是用于此要求的正确构造吗?