info exists
Tells if a variable has a value.
info exists VAR
Description
Gives 1 when the variable VAR has a value, and 0 when it does not. VAR is read as by set: a local variable in a proc, a variable of a namespace with ::, and an element with NAME(KEY). An array has a value, and so has a variable with an empty string.
A variable that upvar or global links to a variable with no value gives 0.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| VAR | variable name | required | The variable or the element of an array. |
Returns
1 or 0.
Examples
% set v 1; info exists v
1
% info exists nope
0
% set e {}; info exists e
1
% array set arr {1 x}; list [info exists arr] [info exists arr(1)] [info exists arr(2)]
1 1 0
% proc f {} {upvar #0 nothere h; info exists h}; f
0
Errors
% info exists
wrong # args: should be "info exists varName"
-errorcode TCL WRONGARGS
% info exists a b
wrong # args: should be "info exists varName"
-errorcode TCL WRONGARGS
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1