Tcl 信息存在
我有一个关于 Tcl 的奇怪案例,也许我只是不明白。 以下代码是在顶层完成的(不在任何过程内部):
if {![info exists g_log_file_name]} {
set g_log_file_name "default.txt"
}
我希望它做的是声明一个具有某个值的全局变量(如果尚未声明)(这可以在其他脚本或 C 中完成)应用)。然而,if 语句总是为假。我在 Tcl 7.4 上运行。
可能是什么问题?
太感谢了。
I have a curious case of Tcl that perhaps I just don't understand.
The following code is done at the top level (not inside of any procedure):
if {![info exists g_log_file_name]} {
set g_log_file_name "default.txt"
}
What I hope it would do is to declare a global variable with some value if it wasn't declared yet (which can be done at some other script or C application). However, the if statement always false. I ran on Tcl 7.4.
What may be the problem?
Thank you so much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,您观察到的原因可能是因为在执行
if
命令时该变量实际上总是未设置。我可以想象的可能原因是:
我不确定您手头上的那个早已被遗忘的 Tcl 版本,但 8.x 有
trace
命令可用于记录对特定变量的访问 - 您可以尝试使用它来查看会发生什么。Hence the reason you observe is probably because the variable is really always unset at the time your
if
command is executed.Possible reasons for this I can imagine are:
I'm not sure abot the long forgotten version of Tcl you have at hand, but 8.x has the
trace
command which can be used to log accesses to a particular variable—you could try to use it to see what happens.