0

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?

Vee
  • 729
  • 10
  • 27

1 Answers1

0

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.

Hai Vu
  • 37,849
  • 11
  • 66
  • 93
  • 2
    Unfortunately, that code seems to be inside the TclDevKit debugger – glenn jackman Jun 18 '14 at 22:21
  • The debugger has a bug? Nooooooooo! (Has it been reported yet?) – Donal Fellows Jun 19 '14 at 09:35
  • 1
    I don't think it's a bug, but the way the Debugger instruments files is rather annoying. When setting file paths with something like [file dirname [info script]] the code will actually return the pathname of the TclDebugger - not the location of the script! So I've had to move my entire working environment into the bin directory of the TclDevKit to get the debugger to work, hahahaha. – Vee Jul 15 '14 at 14:53