Version 2 of namespace current

Updated 2004-02-25 09:07:47

namespace current

Returns the fully-qualified name for the current namespace. The actual name of the global namespace is "" (i.e., an empty string), but this command returns :: for the global namespace as a convenience to programmers.


Wondering: how is namespace current convenient to programmers ? Consider you want to return a fully qualified variable, no matter in which namespace you are.

 return "[namespace current]::variable"

doesn't work for the global namespace;

 return "[namespace current]variable"

only works for the global namespace. If the variable doesn't exist yet, namespace which won't help either. So someone mind explaining to me why exactly this is not inconvenient to programmers ? Seems I got tomatoes on my eyes.

 namespace eval bla { variable v }
 # now how do I give a FQN of v (::bla::v here) as -textvariable ?
 # here [namespace which -variable v] would work.
 # but ...
 namespace eval bla { widget .bla -variable [namespace what-exactly var] }
 # .bla should set ::bla::var

See also:


Category Command - Tcl syntax help