variable
Declare and initialize namespace variables.
Syntax
tcl
variable ?name value ...? name ?value?Parameters
- name: Variable name (simple or namespace-qualified)
- value: Optional initial value for the preceding name
Description
Creates a variable in the current namespace and links a local reference to it. If called inside a procedure within a namespace, creates both the namespace variable and a local alias.
When name is a simple name (not qualified with ::), the variable is created in the current namespace. When name is a fully-qualified name (e.g., ::other::varname), variable creates a local link to that variable in the specified namespace, enabling cross-namespace access. The parent namespace must already exist; otherwise an error is raised.
Examples
Declaring namespace variables
Output
Multiple variables at once
Output
Variable without initial value
Output
Cross-namespace access with qualified names
Output
