'''`[namespace] import`''' imports [routine%|%routines] into the [namespace current%|%current namespace]. ** See Also ** `[namespace origin]`: [return%|%Returns] the name of the routine that an imported routine references. `[ycl%|%ycl ns powerimport]`: Like `[namespace]`, but imports all matching routines whether or not they are exported. ** Synopsis ** '''namespace import''' ''?-'''''force'''''? ?pattern pattern ...?'' ** Documentation ** [http://www.tcl.tk/man/tcl/TclCmd/namespace.htm%|%official reference]: ** Description ** Each ''pattern'' is a qualified name whose the [namespace tail%|%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 [rename%|%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* ====== ** Alternative: `[interp alias]` ** `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 ====== ** Misc ** [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: 1. Have `namespace import` return a list of the commands that are imported. Right now I don't see any easy way to determine what gets imported. ''([DKF]: This is what 8.5 now does, BTW.)'' (What [TIP] [http://www.tcl.tk/cgi-bin/tct/tip/261.html%|%261] specifies is the behavior with no arguments. That's not quite what I'm suggesting.) 1. Alternatively, have `namespace import` take another parameter, perhaps ''-asif'', that tells it to just return the names of what would be imported and to not do the actual import. 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. ** Page Authors ** [PYK]: <> Command | Namespace