This is not necessarily the current version of this TIP.
| TIP: | 142 |
| Title: | Search Path Variable to Lookup Command Names in Namespaces |
| Version: | $Revision: 1.1 $ |
| Author: | Ulrich Schoebel <ulrich dot schoebel at sigos dot de> |
| State: | Draft |
| Type: | Project |
| Tcl-Version: | 8.5 |
| Vote: | Pending |
| Created: | Wednesday, 23 July 2003 |
| Keywords: | namespace, command lookup, search path |
This TIP adds a Tcl variable to define the search path for command name lookup across namespaces.
Command names (as well as variable names) are currently looked up first in the current namspace, then, if not found, in the global namespace.
It is often very useful to hide the commands defined in a subnamespace from being visible from upper namespaces by info commands namespace::*. On the other hand, programmers want to use these commands without having to type a qualified name.
Example:
namespace eval ns1 {
proc p1 {} {
puts "[p2]"
}
}
namespace eval ns1::ns2 {
proc p2 {} {
return hello
}
}
Evaluation of ns1::p1 would currently lead to an error, because p2 could not be found. Even worse, if a procedure p2 exists in the global namespace, the wrong procedure would be evaluated.
Add a variable tcl_namespacePath or, to avoid confusion with variables containing file system paths, tcl_namespaceSearch, that contains a list of namespaces to be searched in that order.
The default value would be [list [namespace current] ::].
In the above example tcl_namespacePath would be set to [list [namespace current] [namespace current]::ns2]. p2 would be found and not unintentionally be substituted by ::p2.
For ease of implementation and, maybe, for programmers convenience it might be useful to always prepend the contents of this variable with [namespace current]. The programmer expects a certain "automatism" for this component of the search path.
Then the default value would be ::.
To be done when this TIP is accepted.
This document is placed in the public domain.
This is not necessarily the current version of this TIP.