Questions tagged [upvar]

23 questions
13
votes
4 answers

how the upvar command works in TCL?

I have a question about upvar command in TCL. Using upvar command, we have have a reference to a global variable or a local variable in other procedure. I saw the following code: proc tamp {name1 name2} { upvar $name1 Ronalod upvar $name2…
user707549
5
votes
3 answers

Difference between upvar 0 and upvar 1 in TCL

Can anyone let me know the difference between upvar 0 and upvar 1 in TCL, how we can use in real time. Kindly, if someone explain with example, it makes me more clear.
velpandian
  • 431
  • 4
  • 11
  • 23
3
votes
3 answers

TCL - return variable vs upvar and modify

Would like to take an advice from TCL professionals for best practice. Say you want to construct a list with a specific data by using a proc. Now which is the best way? proc processList { myList } { upvar $myList list_ #append necessary data…
Narek
  • 38,779
  • 79
  • 233
  • 389
3
votes
3 answers

What purpose does upvar serve?

In the TCL code that I currently work on, the arguments in each procedure is upvar'ed to a local variable so to speak and then used. Something like this: proc configure_XXXX { params_name_abc params_name_xyz} { upvar $params_name_abc abc …
user2311285
  • 437
  • 6
  • 14
3
votes
2 answers

error : Can't read "n" : no such variable in tcl

proc rep {name} { upvar $name n puts "nm is $n" } In the above procedure, 'name' is a parameter which is passed to a procedure named 'rep'. When I run this program I got "error : Can't read "n" : no such variable". Could any one tell me…
Praveen kumar
  • 597
  • 2
  • 14
  • 26
2
votes
1 answer

What is the difference between a TCL namespace and a stack frame?

Upvar creates a link to a variable in a different stack frame, sometimes called a call stack, or a different scope. Upvar is also used to create an alias for a global (or namespace) variable 2. But a namespace is created only by the namespace eval…
Otto Hunt
  • 107
  • 1
  • 7
2
votes
1 answer

Tcl upvar to a variable in another proc

I have two procs: From MAIN I call another proc Glob. $Allforces is a list of lists. proc ::MAIN {} { # something ::Glob $AllForces } proc ::Glob {Input} { upvar $Input AllForces # do something } I get "No such variable" as an…
Lumpi
  • 2,697
  • 5
  • 38
  • 47
1
vote
3 answers

Unable to pass a variable to a procedure using upvar in Tcl

I need a procedure that will be able to access, read and change a variable from the namespace of the caller. The variable is called _current_selection. I have tried to do it using upvar in several different ways, but nothing worked. (I've written…
SIMEL
  • 8,745
  • 28
  • 84
  • 130
1
vote
1 answer

Why does this code with TCL Upvar command generate an error?

So I thought I understood how the TCL upvar command worked, but for some reason I cannot seem to trace why this code generates an error - #!/usr/bin/env tclsh proc run_check {} { set src dut.acore.B2.Vin set conlist1 [list dut.acore.B2.Vin…
Rajat Mitra
  • 167
  • 1
  • 11
1
vote
2 answers

How to access a variable defined in proc 'a' from a different proc 'b' which does not call proc 'a'?

I am trying to execute a tcl script which makes exclusive calls to procs a and b. The two procs are not related to each other. proc a {} { set var1 "a" } proc b {} { # Do something here with: $var1 } # script.tcl a b I do not have access…
vandan
  • 13
  • 2
1
vote
1 answer

Expected TCL: upvar vs namespace variable performance

Is there an expected, by spec/implementation, difference between accessing namespace variables vs. upvar. I have to use a call-back function. I cannot just pass an argument.Empirically, upvar wins. But is that expected, in all reasonable…
user1134991
  • 3,003
  • 2
  • 25
  • 35
1
vote
2 answers

Tcl upvar performance improvement vs. direct pass

This pertains to Tcl 8.5 Say I have a very large dictionary. From performance points of view (memory footprint, etc), assuming that I do not modify the dictionary, should upvar provide a massive performance improvement in terms of memory? I am using…
user1134991
  • 3,003
  • 2
  • 25
  • 35
1
vote
1 answer

Elevating a variable scope without knowing its name

I need to 'upvar' variables from a source'd file (and I don't know their names) Let's say I have a TCL file containing: set v 7 Now this: proc p {} { source t.tcl } p puts $v # => can't read "v": no such variable The file t.tcl must not be…
Gert Gottschalk
  • 1,658
  • 3
  • 25
  • 37
1
vote
1 answer

Usage of namespace/uplevel/global in TCL

I have a script like this : proc subProc1 { } { puts $var1 } proc subProc2 { } { puts $var2 } proc mainProc { args } { # Define many variables subProc1 subProc2 #etc. } I would like subProc1 and subProc2 to have variables…
little-dude
  • 1,544
  • 2
  • 17
  • 33
1
vote
1 answer

tcl proc using upvar resulting in history(nextid)

I'm getting this weird issue. i'm using tcl 8.3 after i define this proc in a tcl shell % proc incr { varName {amount 1}} { puts $varName upvar #0 $varName var puts $varName if {[info exists var]} { set var [expr $var +…
1
2