【发布时间】:2020-08-05 13:23:50
【问题描述】:
我的目标是在我的 tcl 脚本中执行 log base 2,但它提出了一些关于 tcl 如何工作的问题。我需要做这些事情:
- 在我的 tcl 环境中查找可用包列表
- 查找包中可用的程序列表
- 像我们在 Shell 中使用 -h 或 --help 开关一样查找过程的“信息”或“描述”
- 如何将新包添加到我们的 tcl 环境中?是否有 tcl 的软件包可以像 Python(我们使用 pip)一样下载?
现在我尝试自己执行一些命令,跟踪如下:
% info log
error: unknown or ambiguous subcommand "log": must be args, body, class, cmdcount, commands, complete, coroutine, default, errorstack, exists, frame, functions, globals, hostname, level, library, loaded, locals, nameofexecutable, object, patchlevel, procs, script, sharedlibextension, tclversion, or vars
while executing
"info log"
% log(2.71)
error: invalid command name "log(2.71)"
while executing
"log(2.71)"
% expr log(2.71)
0.9969486348916096
% info ::tcl::mathfunc
error: unknown or ambiguous subcommand "::tcl::mathfunc": must be args, body, class, cmdcount, commands, complete, coroutine, default, errorstack, exists, frame, functions, globals, hostname, level, library, loaded, locals, nameofexecutable, object, patchlevel, procs, script, sharedlibextension, tclversion, or vars
while executing
"info ::tcl::mathfunc"
% info ::tcl::mathfunc::log
error: unknown or ambiguous subcommand "::tcl::mathfunc::log": must be args, body, class, cmdcount, commands, complete, coroutine, default, errorstack, exists, frame, functions, globals, hostname, level, library, loaded, locals, nameofexecutable, object, patchlevel, procs, script, sharedlibextension, tclversion, or vars
while executing
"info ::tcl::mathfunc::log"
% expr ::tcl::mathfunc::log(2.71)
error: missing operand at _@_
in expression "_@_::tcl::mathfunc::log(2..."
(parsing expression "::tcl::mathfunc::log(2...")
invoked from within
"expr ::tcl::mathfunc::log(2.71)"
% info
error: wrong # args: should be "info subcommand ?arg ...?"
while executing
"info "
% info library
C:/intelFPGA/18.1/quartus/bin64/tcl8.6
% package names
systemconsole zlib TclOO tcl::tommath Tcl
% ::tcl::mathfunc::rand
0.6648586465347831
% info ::tcl::mathfunc::rand
error: unknown or ambiguous subcommand "::tcl::mathfunc::rand": must be args, body, class, cmdcount, commands, complete, coroutine, default, errorstack, exists, frame, functions, globals, hostname, level, library, loaded, locals, nameofexecutable, object, patchlevel, procs, script, sharedlibextension, tclversion, or vars
while executing
"info ::tcl::mathfunc::rand"
这条踪迹让我感到困惑的是:
- 执行“包名称”返回“systemconsole zlib TclOO tcl::tommath Tcl”,这不包括 ::tcl::mathfunc。这是为什么?这个列表太小了!
- 为什么 log(2.71) 返回“invalid command name”错误,但 expr log(2.71) 有效?
- 为什么 expr ::tcl::mathfunc::log(2.71) 失败但 ::tcl::mathfunc::rand 有效?两者都不是 mathfunc 包的一部分吗?
【问题讨论】:
-
从技术上讲,
log(2.71)是一个有效的函数名。将括号放在这样的名称中只是非常不寻常,因为在使用关联数组时会令人困惑。 -
另外,尝试运行
info commands tcl::mathfunc::*以获取所有函数实现命令的列表。
标签: tcl