tcl7.6 User Commands - @scope
NAME
@scope - prefix for scoped values
SYNOPSIS
@scope namespace varName
@scope namespace command ?arg arg ...?
DESCRIPTION
Any command or variable name starting with @scope is treated
as a scoped value. The associated namespace is activated
before the command is executed or the variable is accessed.
With namespaces, commands and variables are no longer simple
strings; they are names with an associated context. Scoped
values capture the namespace context of a command/variable
in a form that can be passed around at the Tcl language
level. They are usually created by wrapping code fragments
with the code command, and variable names with the scope
command. They are rarely generated by hand.
Any variable name starting with @scope is automatically
recognized as a global variable in the specified namespace.
Access is allowed from any namespace, even if the variable
is protected or private. Scoped variables can be used any-
where that an ordinary variable name is recognized. For
example, the following statements are allowed:
namespace foo {
variable mode "1"
}
set {@scope ::foo mode} 3
puts "value = ${@scope ::foo mode}"
Any command name starting with @scope is automatically exe-
cuted in the specified namespace. If additional arg argu-
ments are included, the command string is built by appending
the extra arg as list elements to the end of the command
string. This preserves the integrity of the arguments,
while keeping the code fragment command as a flat string.
For example:
@scope ::foo {.b configure} -text "Hello World!"
is equivalent to:
namespace ::foo {.b configure -text {Hello World!}}
Since scoped commands are executed in their namespace con-
text, they provide a way to access protected and private
commands from any other namespace. In effect, the @scope
command is a lot like the namespace command, but it allows
extra arguments to be appended to the command.
KEYWORDS
@scope, code, scope, namespace, private, protected, public