Scope is a context within which to resolve names, binding names to values. Tcl is capable of both lexical and dynamic scoping. Tcl requires lexical scope for command resolution, and prefers (or defaults to) dynamic scope for variable resolution within [[[proc]]]. Tcl has partitioned static scopes - a different binding can exist in each static scope for variables and commands with the same name. Tcl has many scopes (''almost'' doubled by the variable/command name partitioning): '''namespace''' is an hierarchal scope for resolving names of [commands] and [variables]. The [variable] command references a variable name in namespace scope. '''global''' scope is a distinguished namespace scope, equivalent to namespace :: in some interpreter, it is also a distinguished call frame sope - equivalent to [upvar] #0. '''hidden''' scope is a per-interpreter scope for [interp] hidden commands '''call frame''' scope is the context of some call frame in the current evaluation. '''proc local''' scope is the context within which all otherwise unqualified variable names referenced in a [proc] are defined. Proc local is a special case of a call frame scope, being the nearest enclosing call frame scope. ---- In summary, there are two major kinds of scoping in tcl - dynamic and lexical (or static) scope. '''dynamic''' scope is accessed by default inside a proc, or by means of [upvar] with unqualified names, and is preferred for variable name resolution. '''static''' or '''lexical''' scope is accessed explicitly by namespace encoded names, the [global] operator, and implicitly by [command invocation] and by the [variable] operator. Command resolution prefers dynamic scope. [RS] has learnt this distinction, however: * '''dynamic scope''' determines variable value at runtime - used in older [Lisp] versions * '''lexical scope''' conserves the value of variables they had at the time a [proc] was defined, for instance in [closures] - considered more advanced in [Lisp] circles. [CMcC] believes this isn't true. Firstly, [closures] can work in either lexically or dynamically scoped languages. Secondly, Scoping is about how one resolves (or ''binds'') free (or ''unbound'') names. Dynamic binding can only occur at runtime, Static binding can sometimes occur at definition time (which is its supposed advantage). In dynamically scoped languages (in, e.g. real [Lisp] :) the call frame is searched for name->value mappings matching some unbound ''name'' - like [upvar]. In lexically scoped languages (in, e.g. Scheme) the definition environment for the currently executing code is searched for those mappings - like tcl's [variable] ---- [Category Concept]