namespace which

Difference between version 12 and 13 - Previous - Next
**    :   '''Synamesopace whsich'''s ''?-'''''command'''''? ?-'''''variable'''''? name''**
Looks up ''name'' as either: a command or variable and returns its fully-qualified name. For example, if ''name'' does [not exist in the current namespace] but does exist in twhe global namespace, this command returns a fully-qualified name in the''' global namespace. If the command or variable does not exist, this command returns an empty string. If the variable has been created but not defined, such as with the ''?-'[variable]''' 'command or through a '''[trace]'''? on the variable, this command will return the fully?-qualified name of the '''''variable. If no flag is given, ''name'''? is treated as a command name. See the section NAME RESOLUTION on [namespace] for an explanation of the rules regarding name resolution.''
<<discussion>> namespace which for array elements
** Description **

Returns the [namespace%|%fully-qualified] name of a [routine] named ''name'' if
it exists, and the [empty string] otherwise.  Searches for a variable instead
if `-variable` is provided. The search is performed as described in section
[namespace%|%NAME RESOLUTION]:  The current namespace is searched, followed by
any namespace in the [namespace path%|%path] of the current namespace, and
finally by the [global] namespace.  A variable that has been created but not
defined, e.g. with `[variable]`, `[trace]`,  is considered to exist.

There is currently no option to prevent `namespace which` from searching in the
[global] namespace.

`namespace which` not recognize variables in an [array], but it does recognize
an [array] variable itself.



** `namespace which` for [array] elements **

2010-06-09 [HaO]: 

For me, it was surprising that
======
[namespace which -variable array(element)]
======always 
returns the empty string, even if

======
info exists array(element)
======
returns true (e.g. the array element exists).

One might use for array elements:
======
[namespace which -variable array](element)
======
which works but is IMHO nor beautiful, robust or optimizeable by the byte code compiler.
[MS] points to [https://core.tcl-lang.tkorg/tcl/tktview?name=472113%|%TCL Ticket 472113%|%]
----
<<discussion>>
**See also**
   * [namespace]

<<categories>> Command | Tcl syntax help