tcl7.6 User Commands - import
NAME
import - change the "import" list for a namespace
SYNOPSIS
import option ?arg arg ...?
DESCRIPTION
The import command is used to query or modify the import
list for the current namespace context. Command, variable
and namespace names are sought first in the current
namespace context, then in all imported namespaces. This
means that commands/variables can be referenced in an
imported namespace without the usual namespace qualifiers.
When a namespace is added to the import list, it acts as if
it were a part of the namespace that imports it.
By default, each namespace imports its parent. This allows
commands and variables at the global scope to be accessed
transparently in child namespaces. Frequently-used
libraries can also be added to the import list, but it is a
good idea to import namespaces sparingly. If each namespace
imported all of the others, there would be very little
advantage to using namespaces.
By default, namespaces are imported in a "public" mode.
This means that public commands/variables can be accessed
transparently, but protected and private elements remain
hidden. Namespaces can also be imported in a "protected"
mode. This means that public and protected
commands/variables can be accessed transparently, but
private elements remain hidden. There is no way to import
in a "private" mode, so private elements always remain hid-
den from other namespaces.
The option argument determines what action is carried out by
the command. The legal options (which may be abbreviated)
are:
import add name ?name...? ?-where pos...?
Adds one or more namespace name references to the
import list in the current namespace context. Each
name reference may be a namespace name, or a list with
two elements: the first element is the namespace name,
and the second is the import protection level, either
"public" or "protected".
The -where flag can be used to specify where the list
of name's should be added in the existing import list:
-after pos ?pos...?
Namespace name's are inserted after the position
of namespace pos on the list. If more than one
pos namespace is specified, the name's are
inserted after the pos nearest the end of the
list.
-before pos ?pos...?
Namespace name's are inserted before the position
of namespace pos on the list. If more than one
pos namespace is specified, the name's are
inserted before the pos nearest the start of the
list.
import all ?name?
Returns the namespace search path used for
command/variable resolution in namespace name, or in
the current namespace context if name is not specified.
This is the list of namespaces found by starting at the
target namespace, and following its tree of import
references. Each element on the return list is itself
a list containing a namespace name and its import pro-
tection level (public or protected).
import list ?importList?
Returns the import list in the current namespace con-
text. Each element on the return list is itself a list
containing a namespace name and its import protection
level (public or protected). If a new importList is
specified, then the import list is set to this. The
elements of importList can be simple namespace names or
two-element lists with a namespace name and its import
protection level.
import remove name ?name...?
Removes one or more namespace name's from the import
list in the current namespace context. Each name
reference can be simple namespace name or a two-element
list with a namespace name and its import protection
level.
KEYWORDS
namespace, import, private, protected, public