Tcl: [info level] vs. [info frame]

What is the difference between frames and run levels?

I wrote a small example to find out. I realized that the level number increased every time proc was called.

On the other hand, the frame number increased at each

  • proc call
  • source team
  • eval command
  • and etc.

For this reason, I began to think of levels as a subset of frames. Now I am debugging some real code, and I realized that the level number can increase without increasing the number of frames. How to understand this material?

+4
source share
1 answer

, info level, , upvar uplevel . , "" Tcl - , uplevel, , ( ) namespace eval; info level , .

info frame - - , , - . , .

. .

% proc foo {y} {set x 1;bar $y $x $y}
% proc bar {a b args} {
    puts [info level 0]
    puts [info level -1]
    puts [info frame 0]
    puts [info frame -1]
}
% foo 3
bar 3 1 3
foo 3
type proc line 4 cmd {info frame 0} proc ::bar level 0
type proc line 1 cmd {bar $y $x $y} proc ::foo level 1

, , info level , , info frame , .

:

% proc foo {y} {set x 1;grill $y $x $y}
% proc grill {a b c} {uplevel 1 [list bar $a $b $c]}
% proc bar {args} {
    for {set i 1} {$i<=[info level]} {incr i} {puts $i-->[info level $i]}
    for {set i 1} {$i<=[info frame]} {incr i} {puts $i==>[info frame $i]}
}
% foo 3
1-->foo 3
2-->bar 3 1 3
1==>type eval line 1 cmd {foo 3} level 2
2==>type proc line 1 cmd {grill $y $x $y} proc ::foo level 1
3==>type proc line 1 cmd {uplevel 1 [list bar $a $b $c]} proc ::grill
4==>type eval line 1 cmd {bar 3 1 3} proc ::grill
5==>type proc line 3 cmd {info frame $i} proc ::bar level 0

, info level , uplevel, info frame. info level , . ( , , source, info frame .)

+4

All Articles