namespace which
Gives the full name of a command or a variable.
namespace which ?-command? ?-variable? NAME
Description
Looks up NAME from the current namespace with the rules of a call, and gives the full name of the command it finds, or an empty string. With -variable, it looks up a variable in place of a command. -command is the default. Only one of the two flags can be given.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| NAME | command or variable name | required | The name to look up. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
-command | flag | none | Looks up a command; the default. |
-variable | flag | none | Looks up a variable. |
-command
Looks up a command; the default.
NAME is the name of a command.
% namespace which -command set
::set% namespace which -bogus x
wrong # args: should be "namespace which ?-command? ?-variable? name"
-errorcode TCL WRONGARGS-variable
Looks up a variable.
NAME is the name of a variable. In a namespace, a name with no :: is a variable of that namespace, or of the global namespace when the namespace has none.
% set gv 1
> namespace which -variable gv
::gv
% namespace eval wv {variable x 1}
> namespace eval wv {namespace which -variable x}
::wv::x
% namespace which -variable nosuchvA NAME that is not found gives an empty string.
Returns
A full name, or an empty string when NAME is not found.
Examples
% namespace which set
::set
% namespace which nosuch
% namespace eval wv {proc f {} {}}
> namespace eval wv {namespace which f}
::wv::f
Errors
% namespace which
wrong # args: should be "namespace which ?-command? ?-variable? name"
-errorcode TCL WRONGARGS
% namespace which -command -variable x
wrong # args: should be "namespace which ?-command? ?-variable? name"
-errorcode TCL WRONGARGS
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1