我们如何找到tcl环境中存在的包以及它们的存储位置,以及如何包含新包?

我们如何找到tcl环境中存在的包以及它们的存储位置,以及如何包含新包?,tcl,Tcl,我的目标是在我的tcl脚本中执行log base 2,但它提出了一些关于tcl如何工作的问题。我需要做这些事情: 查找my tcl环境中可用软件包的列表 在软件包中查找可用的程序列表 查找过程的“信息”或“描述”,就像我们在Shell中使用-h或--help开关一样 如何将新包添加到我们的tcl环境中?tcl有没有像Python(我们使用pip的地方)一样可以下载的包 现在,我尝试自己执行一些命令,跟踪如下: % info log error: unknown or ambiguous subc

我的目标是在我的tcl脚本中执行log base 2,但它提出了一些关于tcl如何工作的问题。我需要做这些事情:

  • 查找my 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。为什么呢?这个列表太小了
  • 为什么日志(2.71)返回“无效命令名”错误,而expr日志(2.71)正常工作
  • 为什么expr::tcl::mathfunc::log(2.71)失败了,但是::tcl::mathfunc::rand工作了?这不是mathfunc包的一部分吗
  • 查找包
  • Tcl等待构建包列表,直到您请求一个它目前不知道其名称的包
    catch{package require theresnosuchpackage}
    应该主要填充列表

    但是,有些包存储为Tcl模块,并且从未进入列表。它们使用更有效的加载机制,但在格式上有一定的限制
    tcl::tm::path list
    将给出一个目录列表,在其中可以找到这些目录,包名和版本将由此构建到一个文件中

    我不喜欢这样,即使只是为了维护和发现的目的,也没有一种方法可以整齐地获得这些模块的列表

  • 表达式中的函数
  • expr
    命令从以下位置重写对
    log(1.23)
    函数的调用:

    expr { log(1.23) }
    
    打电话给:

    expr { [tcl::mathfunc::log [expr { 1.23 }]] }
    
    最终相当于:

    expr { [tcl::mathfunc::log 1.23] }
    
    tcl::mathfunc::log 1.23
    
    这反过来实际上相当于:

    expr { [tcl::mathfunc::log 1.23] }
    
    tcl::mathfunc::log 1.23
    
    (这里的“虚拟”是一个真正的数字,因为log函数返回一个浮点数。与自定义函数有一些细微的技术差异。)

  • 请注意,括号在上述调用中消失了它们只是表达式的语法。从技术上讲,表达式是嵌入在Tcl中的自己的小语言(而这反过来又嵌入了Tcl)

    rand
    的重写只会删除括号,因为它不带任何参数


  • 从技术上讲,
    log(2.71)
    是一个有效的函数名。在这样的名称中加括号是很不寻常的,因为在使用关联数组时会让人困惑。另外,试着运行
    info commands tcl::mathfunc::*
    ,以获得所有函数实现命令的列表。我可以看出tcl在很多方面都不同于C我很感兴趣。您能否提供一个不会出现在
    包名
    输出中的模块示例?