Jump to content

Scope modifiers: Difference between revisions

→‎{{header|Tcl}}: Describe Tcl's command scoping
(→‎Tcl: Added implementation)
(→‎{{header|Tcl}}: Describe Tcl's command scoping)
Line 117:
 
=={{header|Tcl}}==
===Variables===
In Tcl procedures, variables are local to the procedure unless explicitly declared otherwise (unless they contain namespace separators, which forces interpretation as namespace-scoped names). Declarations may be used to access variables in the global namespace, or the current namespace, or indeed any other namespace.
 
Line 157 ⟶ 158:
}
[example new] showOff</lang>Output:<pre>variable objVar holds "This is an object variable"</pre>
===Commands===
Tcl commands are strictly always scoped to a particular namespace (defaulting to the global namespace, which is just a normal namespace in a somewhat privileged position). Commands are looked up in the current namespace first, then according to the current namespace's path rules (always empty prior to Tcl 8.5), and then finally in the global namespace. This effectively puts the global namespace in the scope of every namespace (though override-able in every namespace as well). By convention, library packages are placed in namespaces other than the global one (except for legacy cases or a single package access command) so that they don't cause unexpected conflicts; typically the global namespace is reserved for the Tcl language and user applications.
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.