Questions tagged [upvar]
23 questions
0
votes
1 answer
Why does this upvar refer to the global context? Or can upvar be used in a coroutine?
The following strained example, in attempt to match my real situation, completes successfully but not the way I'd like it to; nor do I understand why or can find an answer in one of my books.
I can see that proc func was called from the global level…

Gary
- 2,393
- 12
- 31
0
votes
2 answers
Tcl: Why is the dollar sign used in the first argument to `upvar`?
The tcl docs provide the following example on how to use the upvar command:
proc add2 name {
upvar $name x
set x [expr {$x + 2}]
}
Inside this procedure, x acts as a reference to the variable name which belongs to the scope outside of…

user32882
- 5,094
- 5
- 43
- 82
0
votes
1 answer
Tcl - Append or Modify a nested list in called function
I have a nested list in the parent function and I want to append a few more elements to it inside one of the called functions
proc myparent {
set mylist {}
foreach elem $listelements {
lappend mylist $elem
}
#at this point, mylist…

dgarg
- 318
- 1
- 3
- 13
0
votes
2 answers
Tcl upvar and uplevel in performance
Let's say I have a variable which is one level up, which I just want to query its' value. I have two options:
uplevel { set var_name }
Or:
upvar var_name
If I need to query the variable just once, and not change it, which one should be faster?

user1134991
- 3,003
- 2
- 25
- 35
0
votes
5 answers
Assigning to a variable in a parent context in Bash
I want to write a function similar to the read built-in, where I pass a variable name as an argument, and the function returns its result into the variable named.
I tried doing it like this:
#!/bin/bash
FIB_CALLS=0
# usage: fib $variable $index
#…

user3840170
- 26,597
- 4
- 30
- 62
0
votes
1 answer
Tcl/Tk: scope of variables for a function within a function
I'm getting lost on scoping variables in Tcl. I've got two procs I've written and stored in a file that I want to call in another script I'm writing. In my sourced file (which I'll call bar.tcl), I'm using upvar to define a bunch of variables at…

the_meter413
- 231
- 3
- 19
0
votes
1 answer
how do I update a variable via a tk window by name
Consider the following situation:
namespace eval ::mydialog {}
proc ::mydialog::show {w varName args} {
upvar 1 $varName theVar
# now I can access theVar
# (1)
# code defining/creating my window
# here some widgets for user…

PeterE
- 5,715
- 5
- 29
- 51
-1
votes
2 answers
Tcl upvar issue
Im trying to modify a variable using upvar (in an upward stack), but the value of the variable is passed to the procedure and not the variable name.
I cannot change what is passed, since it is already implemented widely on the program.
Is there a…

Guy
- 25
- 3