Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2002-03-28
01:09 • Ticket [535709ffff] package ctrl over namespace placement status still Ope... artifact: 352f760e60 user: dgp
2002-03-27
13:30 • New ticket [535709ffff]. artifact: e93ba08584 user: muonics

[package] ctrl over namespace placement

Open535709ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 25 years ago
Descriptionplain2002-03-27 13:30:42
Allow the "package require" command to take an 
argument for asserting control over the placement of 
loaded namespaces that are defined with relative names 
(ie., not explicitly off the root namespace as 
in ::MyNamespace).

For example, if you know that a particular package's 
Tcl code is written in a namespace-placement-safe 
manner (e.g., through applicable use of "namespace 
code", etc.), it should be possible to have an 
application that is using that package place it 
wherever it wants in the namespace heirarchy, to avoid 
namespace collision without modifying the source code 
of the package.

For example, if my application uses two packages that 
both want to define the namespace "tools", your 
options are either:

1. Edit the source code to rename their namespaces to 
e.g. "contrib1::tools" and "contrib2::tools" 
or "tools1" and "tools2".

2. Use "namespace eval contrib1 { source 
package1/tools.tcl" (likewise for package 2), instead 
of the package mechanism.

Instead, it would be useful to use a command such as:

package require package1 -in contrib1
package require package2 -in contrib2

Then, if package1 and package2 are both written to 
define the "tools" namespace, they'd automatically be 
placed within the desired parent namespace.

The following does not work...

namespace eval contrib1 {
    package require package1
}
namespace eval contrib2 {
    package require package2
}

...because through package ifneeded etc. the files 
listed in pkgIndex.tcl will be sourced in the global 
context.

This would be particularly useful in cases where a 
package contains multiple namespaces, or in re-
packaging a set of packages as a single package.  In 
the latter case, some namespace-like heirarchy to 
package names might also be useful.
dgpplain2002-03-28 01:09:12
Logged In: YES 
user_id=80530

The ideas in this request are interesting,
but I think they bump up against
the design in [package] that at most one
version of each package can be loaded at
one time in each interpreter.

Since I can only have one version of the
package "foo" loaded, even though many 
other packages might want to make use of
it, then it is important that the commands
of "foo" are defined in a well-known place,
conventionally, the ::foo namespace.

So, I believe that attempting to fulfill
this request would require a pretty fundamental
re-thinking of how [package] works.  Not
likely to happen soon.
Log in (anonymous is fine) to add a comment.