'''`[namespace] import`''' imports commands into a namespace. ** Synopsis ** '''namespace import''' ''?-'''''force'''''? ?pattern pattern ...?'' ** Documentation ** [http://www.tcl.tk/man/tcl/TclCmd/namespace.htm%|%official reference]: ** Description ** Each ''pattern'' is qualified name, the tail of which is a `[glob]`-style pattern that selects the commands in the specified namespace. `[glob]`-style characters only have their `[glob]` pattern meanings in the tail component of ''pattern''. In the namespace qualifiers of ''pattern'' they have no special meaning. The commands that match the pattern and that are exported from the specified namespace are imported into the current namespace, meaning that a new command is created in the current namespace as an alias to the exported command in the specified namespace. [rename%|%renaming] such an alias does not break the alias. `[namespace] import` normally returns an error if an imported command conflicts with an existing command. However, if the '''`-force`''' option is given, imported commands will silently replace existing commands. `namespace import` has snapshot semantics: Only matching commands that are '''currently defined''' in the exporting namespace are imported. In other words, you can import only the commands that are in a namespace at the time when `namespace import` is executed. To import a command, `[namespace] import` must be called after that command has been exported. This is in contrast to `[namespace export]` whose patterns apply to all commands in the namespace, regardless of when they were defined. For use cases where it is an alternative, `[namespace path]` is preferred to `namespace import`. ([PYK] 2014-06-22: rationale needed). '''Examples''': ====== namespace import ::foo::x namespace import a::p* ====== ** Suggestion: Determine the Target of an Imported Command ** [PYK] 2014-08-15: Currently, calling `[namespace import]` without any arguments causes it to return a list of commands that are imported, but there is no way to determine what namespace the commands are imported from. If `[namespace import]` instead reuturned the fully-qualified name of each imported command, it could be used for this purpose. ** 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 the 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], actually. 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 allow reduction of false positives for unknown commands. ** See Also ** [namespace]: <> Command | Tcl syntax help