Version 9 of namespace path

Updated 2009-11-02 14:19:12 by dkf
namespace path ?namespaceList?

Returns the path of the current namespace, or sets it to the list of namespaces namespaceList if that argument is given. The path of a namespace is used to “resolve” command names that do not start with a namespace qualifier (i.e., are not fully qualified) when those commands are not present in the current namespace.


wdb This command shows or extends the namespace where an input command is searched in.

In this example, the namespace is extended:

% namespace path "tcl::mathfunc tcl::mathop"
% 

Now, you can input math-related commands as follows:

% hypot 3 [+ 2 2]
5.0
% 

In this example, the namespace extension is shown.

% namespace path
::tcl::mathfunc ::tcl::mathop
% 

Note that the namespaces argument is one proper list. It is not possible to input namespaces as single arguments. (Is it a matter of discussion if that should be possible?)

Note that each namespace (including the global namespace) has a different path. For example:

% namespace eval test {namespace path ::tcl::mathop}
%

inside newly created namespace test, path is extended to ::tcl::mathop. Now, check it out:

% namespace eval test {namespace path}
::tcl::mathop
%

Indeed, path is extended. Now check it in namespace ::

% namespace path
%

In namespace ::, obviously there is no path extension. Check if ::tcl::mathop::+ is known in namespace test:

% namespace eval test {+ 5 6}
11
%

Check the samein namespace :: leads to failure:

% + 5 6
invalid command name "+"
%