O'Reilly logo

Practical Programming in Tcl & Tk, Third Edition by Brent B. Welch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Nested Namespaces

Namespaces can be nested inside other namespaces. Example 14-3 shows three namespaces that have their own specific variable x. The fully qualified names for these variables are ::foo::x, ::bar::x, and ::bar::foo::x.

Example 14-3 Nested namespaces.
namespace eval foo {
   variable x 1      ;# ::foo::x
}
namespace eval bar {
   variable x 2      ;# ::bar::x
   namespace foo {
      variable x 3   ;# ::bar::foo::x
   }
   puts $foo::x      ;# prints 3
}
puts $foo::x         ;# prints 1

Partially qualified names can refer to two different objects.

In Example 14-3 the partially qualified name foo::x can reference one of two variables depending on the current namespace. From ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required