NAME
scope - capture the namespace context for a variable
SYNOPSIS
scope string
DESCRIPTION
Creates a scoped value for the specified string, which is usually a variable name. A scoped value is a list with three elements: the "@scope" keyword, a namespace context, and the value string. For example, the command
namespace foo {
scope "x"
}
produces the scoped value:
@scope ::foo x
Note that the scope command captures the current namespace context. If the string is itself a scoped value, then the current context is ignored and the string is returned directly.
Ordinary variable names refer to variables in the global namespace. A scoped value captures a variable name together with its namespace context in a way that allows it to be referenced properly later. It is needed, for example, to wrap up variable names when a Tk widget is used within a namespace:
namespace foo {
private variable mode 1
Scoped variables can be used anywhere that an ordinary variable name is recognized. For example, the following statements are allowed:
set {@scope ::foo mode} 3
puts "value = ${@scope ::foo mode}"
Note that scoped variables by-pass the usual protection mechanisms; the name "@scope ::foo mode" can be used in any namespace context to access the "foo::mode" variable, even though it is private.
KEYWORDS
@scope, code, namespace, private, protected, public