beetlebug▾
/

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

ArgumentTypeDefaultDescription
NAMEcommand or variable namerequiredThe name to look up.

Options

OptionTypeDefaultDescription
-commandflagnoneLooks up a command; the default.
-variableflagnoneLooks 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 nosuchv

A 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

See also