namespace import imports routines into the current namespace.
namespace import ?-force? ?pattern pattern ...?
Each pattern is a qualified name whose the tail is a glob-style pattern that selects routines in that namespace. For each routine whose name matches the pattern and which is exported, namespace import creates in the current namespace a special routine by the same name that references the original routine. The namespace indicated in pattern must exist but it is not an error for the pattern to match no routines.
The association between an exported routine and an imported routine remains intact even if the exported routine is no longer exported, or either the original routine or the imported routine is renamed. If the original routine is replaced with a new routine, the imported routine then references the new routine. Deleting the imported routine does not cause the deletion the original routine but deleting the original routine causes the deletion of any imported routines.
Unlike namespace export, which applies to all matching existing or future routines, namespace import only imports existing exported routines.
namespace import returns an error if an imported routine conflicts with an existing routine. If -force is given, namespce import replaces existing routines instead.
namespace import with no arguments returns a list of routines that reference other routines.
DGP: namespace path and namespace import offer different mechanisms for access to commands in other namespaces. Use the one that does what you want. There's no general preference, only the particular preference of each programmer, guided by needs and taste.
Examples:
namespace import ::foo::x namespace import a::p*
namespace import only imports exported commands, and also matches patterns rather than comparing for equality. interp alias can be used if these behaviours are not desired:
interp alias {} ::name::of::somecommand {} ::name::of::link
escargo 2006-12-04: I tested this to see what namespace import returns, and it didn't return anything. There are two behaviors that I think might be useful that aren't implemented:
My motivation has to do with Nagelfar. The second option would allow a code analyzer to follow along with "package require" and "namespace import" to discover code that would be known to the code being analyzed. This would reduce false positives for unknown commands.