Sujet : Re: upvar and uplevel - help
De : user153 (at) *nospam* newsgrouper.org.invalid (Arjen)
Groupes : comp.lang.tclDate : 16. Mar 2025, 15:33:16
Autres entêtes
Message-ID : <1742135596-153@newsgrouper.org>
References : 1
User-Agent : Newsgrouper/0.7.0
sundar <
user2276@newsgrouper.org.invalid> posted:
But is there a way to make the 'upvar' use any variable (table_data, list_data)
where we don't have to make the required changes at each place where the 'templeat'
is needed?
Any other suggestion to refactor is also most welcome.
Yes, most certainly:
```
proc render {v w} {
upvar $v _v
upvar $w _w
set _v "V 1"
set _w "W 2"
}
# Before render ...
set v A
set w B
puts "$v -- $w"
render v w ;# Pass the names, not the values - then we can change the values
puts "$v -- $w"
```
It is a rather silly example, but the secret is that you pass the *name*
of the variables and not the value.