A level is a command evaluation context.
For the evaluation of most commands, a new level is created and the command evaluated at that level. A level maintains the following four notions:
- The current namespace
- The current variable table
- For most commands, the current variable table is the local variable table that exists only for the duration of the command, and is only accessible to commands in scripts evaluated at the current level. For a few commands such as namespace eval the variable table of the current namespace is the current variable table.
- The current command
- The sequence of previous levels
A level could be called a stack frame, but that term used when discussing constructs in the implementation of Tcl, while level is used to discuss the behaviour of a Tcl interpreter.
Commands Related to Levels
Some commands manipulate the current level or reference resources at other levels. Here is a brief description of such commands:
- info level
- Provides information about the current and previous levels.
- namespace eval
- Creates a new level, associates that level with the indicated namespace, and evaluates a script at that level.
- Arranges for a level to be created, arguments to the command to be assigned in the current variable table, and for the body of the procedure to be evaluated at the new level.
- Modifies the current variable table. At a level associated with a namespace if the specified variable doesn't exist at that level, but does exist at the global level, modifies the global variable table instead. This behaviour is now considered a mistake to be fixed in some future version of Tcl.
- Arranges for a script to be evaluated at some level, which is resolved relative to the current level.
- upvar and namespace upvar
- Each of these commands modifies a variable table, which is resolved relative to the current level.
- Modifies the variable table of the current level.
- Many ways to eval
- Whenever a script is evaluated, a level is involved.
- An Eagle-only extension to uplevel.