首页 > 解决方案 > 使用 Tcl info procs 返回值

问题描述

鉴于 not_there 没有我期望的过程

[info procs not_there] eq ""

返回 0,但我看到

empty command name ""

有人可以解释我的概念错误吗?

标签: error-handlingsyntax-errorruntime-errortcl

解决方案


您的这份声明:

[info procs not_there] eq ""

将首先info procs not_there由 Tcl 解释器评估。接下来,解释器将评估此语句的等效项:

"" eq ""

...其中第一个单词""不是有效命令。

在 Tcl 语句中,第一个单词必须始终是命令。命令 arg arg arg...

您缺少的是expr在开始时使用命令

expr {"" eq ""}                       --> 1
expr {[info procs not_there] eq ""}   --> 1

顺便说一句,语句expr的条件参数中隐含了:if

if {[info procs not_there] eq ""} {
     puts "This is not a proc"
}

推荐阅读