Version 17 of Namespace resolution of Variables & Procedures

Updated 2012-06-29 01:52:56 by RLE

The following code example illustrates how different types of namespace path addressing effects what is being accessed (Variables) or executed (Procedures).

Tom Krehbiel


 set Variable "::Variable"

 proc TestProc {} {
     puts "::proc"
 }

 namespace eval Namespace {
     namespace eval Namespace {
         variable Variable "::Namespace::Namespace Variable"
         proc TestProc {} {
             puts "::Namespace::Namespace proc"
         }
     }
     variable Variable "::Namespace Variable"
     proc TestProc {} {
         puts "::Namespace proc"
     }
     proc test0 {} {
         puts "$::Variable"
     }
     proc test1 {} {
         puts "$::Namespace::Variable"
     }
     proc test2 {} {
         puts "$Namespace::Variable"
     }
     proc test3 {} {
         ::TestProc
     }
     proc test4 {} {
         TestProc
     }
     proc test5 {} {
         Namespace::TestProc
     }
 }

 % Namespace::test0
 ::Variable

 % Namespace::test1
 ::Namespace Variable

 % Namespace::test2
 ::Namespace::Namespace Variable

 % Namespace::test3
 ::proc

 % Namespace::test4
 ::Namespace proc

 % Namespace::test5
 ::Namespace::Namespace proc

What's special about {}

 % set {}
 can't read "": no such variable
 % namespace eval ai {
    variable {}
    set {} 1
   }
 1
 % set {}
 1
 % namespace eval ai {
    variable y
    set y 1
   }
 1
 % set y
 can't read "y": no such variable

RHS This seems like something that should probably be filed as a bug, unless there's something I'm missing.

MS cannnot reproduce this behaviour; neither with HEAD (2004-10-19) nor with tcl8.4.6.

RHS Indeed, I cannot reproduce it either (8.4 or 8.5). Can you (the original poster) show it again with an [info patchlevel]?

[Original Poster] sorry my bad. I usually try Tcl interactively inside tkcon on my debian desktop, so it seems this is a tkcon bug, I am running debian sarge, and this was tkcon 2.4, this bug seems to have been solved in newer tkcon (well at least on the tkcon that ships with Active-state tcl 8.4.7). Again sorry for any distrubance.