Tcl Source Code

View Ticket
Login
Ticket UUID: 472113
Title: [namespace which -var] fails for ary(i)
Type: Bug Version: obsolete: 8.4a3
Submitter: hartweg Created on: 2001-10-17 15:41:42
Subsystem: 21. [namespace] Assigned To: msofer
Priority: 6 Severity: Minor
Status: Open Last Modified: 2017-05-16 07:18:48
Resolution: None Closed By: nobody
    Closed on:
Description:
[namespace which -variable ary(i)] returns a null 
string even when ary(i) exists! This is a major pain
when trying to get fully scoped variable names to give 
to widgets. Here is a script snippet that shows the 
eror:
User Comments: oehhar added on 2017-05-16 07:18:48:

Sebres wrote:

I guess, it should rather return "" in this case, because currently "namespace which" will never produce an error (by valid command syntax).

You are right. Personnally, I can not understand the usage for this. I would like to have an error instead of an empty return.

Thats why I did not find a bug for monthes. I wrote:

ttk::radiobutton ... -variable [namespace which -variable a(b)]

Clearly an error, but no error raised and it just does not work.

Thanks, Harald


sebres added on 2017-05-15 17:56:00:

check if it is an array. If not -> error
I guess, it should rather return "" in this case, because currently "namespace which" will never produce an error (by valid command syntax). It would be also similar to "no error" (just empty return) by following code:
unset -nocomplain novar
namespace which -variable novar


oehhar added on 2017-05-15 11:46:42:

Miquel Sofer wrote:

(2) It's not so clear to me what the correct fix would be:
what should happen if the array itself exists, but the array
element does not? In your script, what is the expected
result of adding a line
   puts "4 - [namespace which -variable ary(k)]"
According to the man page, the return should be "" - is this
what you're expecting?

Let me express my expectation. [namespace which -variable ary(k)] should do the following:

  • resolve "ary" in the local scope
  • check if it is an array. If not -> error
  • format the result the same way as [namespace which -variable ary](k). This means, that the existence of the given array index must not exist and is not relevant. The existance of the array and its scope is important.


msofer added on 2006-10-01 22:07:23:
Logged In: YES 
user_id=148712

This cannot be fixed at reasonable cost without changing the
Var struct: an array element does not know it's containing
array, even though it knows its hashtable.

This will probably not happen until Tcl9. Leaving the bug
open to fix at that time.

msofer added on 2002-08-08 03:13:25:
Logged In: YES 
user_id=148712

(1) Sorry, this bug somehow flew under my horizon :( 

(2) It's not so clear to me what the correct fix would be:
what should happen if the array itself exists, but the array
element does not? In your script, what is the expected
result of adding a line
   puts "4 - [namespace which -variable ary(k)]"
According to the man page, the return should be "" - is this
what you're expecting?

(3) Depending on the answer to (2), a workaround involving
[info exists] may be the solution for now.

hartweg added on 2001-10-17 22:58:23:
Logged In: YES 
user_id=338658

Got submitted to quick...
namespace eval a {
  variable ary
  set ary(i) v
  puts "1 - [namespace which -variable ary]"
  set x ary
  set y ary(i)
  puts "2 - [namespace which -variable $x]"
  puts "3 - [namespace which -variable $y]"
 }