Tcl/Tk - can't read "UserArray": variable is array

1.2k Views Asked by At

I am using ActiveState's TclDevKit debugger to look through my code but at one point in the execution of the program I get the following error:

can't read "UserArray": variable is array
    while executing
"set UserArray"
    ("uplevel" body line 1)
    invoked from within
"DbgNub_uplevelCmd DbgNub_uplevelCmd $args"
    invoked from within
"uplevel 1 [list set $name]"
    (procedure "DbgNub_TraceVar" line 53)
    invoked from within
"DbgNub_TraceVar 1 array UserArray time1_satOTRS1,2 w"
    (write trace on "UserArray(time1_satOTRS1,2)")
    invoked from within
"set UserArray($item,$window) $profile_array($item)"

This error utterly baffles me because as I understand Tcl/Tk, what I am doing is completely valid and legal. The code goes:

foreach item [array names profile_array] {
    set UserArray($item,$window) $profile_array($item)
}

In Tcl one is allowed to read from and write to an index in an array, I don't think there should be an error here... Am I missing some detail?

1

There are 1 best solutions below

3
On

In your code, at the line:

uplevel 1 [list set $name]

I guess that in your case, $name == "UserArray". The above statement will be executed at the previous stack frame as:

set UserLevel

which does not make sense, as UserLevel is an array--that's what the error message is trying to tell you. I wonder if you really mean:

upvar 1 $name UserArray

in order to access the array from a proc.