Tcl:[信息级别] vs. [信息框架] [英] Tcl: [info level] vs. [info frame]

查看:22
本文介绍了Tcl:[信息级别] vs. [信息框架]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

框架和执行级别之间有什么区别?

What is the difference between frames and levels of execution?

我写了一个小例子来了解一下.我意识到每次调用 proc 时级别编号都会增加.

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

另一方面,帧数每增加一次

On the other hand, the frame number was incremented on every

  • 过程调用
  • 源命令
  • eval 命令

出于这个原因,我开始将关卡视为帧的子集.现在我正在调试一些现实生活中的代码,我意识到级别数可以增加而帧数也不会增加.如何理解这些东西?

For this reason, I started to think of levels as of a subset of frames. Now I'm debugging some real-life code and I realized that the level number can increase without the frame number being increased too. How to make sense of this stuff?

推荐答案

info level 所讲的堆栈级别很重要,因为它们是您可以使用的级别upvaruplevel 访问.这意味着 Tcl堆栈"真的是一棵树,因为您可以使用 uplevel 上升到更高的级别并开始一个新的分支,每一步更深通过对过程(或类似过程的事物)的调用或对 namespace eval 的调用进行;info level 命令真正讨论的是一直追溯到根的当前分支.

Stack levels, which is what info level talks about, are the important ones, because they're the ones that you can use upvar and uplevel to access into. This means that the Tcl "stack" is really a tree, since you can use uplevel to go up to a higher level and start a new branch, with each step deeper being taken by a call to a procedure (or procedure-like thing) or a call to namespace eval; the info level command really talks about the current branch traced all the way back to the root.

info frame 命令以不同的方式遍历框架树——我认为它使用了实际堆叠它们的方式,框架可以出现两次——并报告有关每个帧的非常不同的信息.就我个人而言,我只是觉得它对调试很有用.

The info frame command walks the tree of frames rather differently — I think it uses the actual way in which they are stacked, with frames being able to appear twice — and reports very different information about each of those frames. Personally, I only really find that it is useful for debugging.

让我们尝试一个简单示例.这是一个互动环节.

Let's try a simple example. This is an interactive session.

% 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正在报告该级别当前正在做什么.

OK, as you can see, info level is reporting the actual values that were used and does not report itself, whereas info frame is reporting what that level is currently doing.

这是一个更复杂的例子:

Here's a more complex example:

% 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 会报告更多信息.)

As you can see, info level does not see that the uplevel happened, but info frame does. But only info level can really tell you what the arguments are. (Note that if you put the code in a file that you source, info frame reports even more information.)

这篇关于Tcl:[信息级别] vs. [信息框架]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆