How do you list all the namespaces in an instance of TCL?

蓝咒 提交于 2019-12-07 16:46:02

问题


How do you list all the namespaces loaded in an instance of tclsh?

Chenz


回答1:


Try running this proc from the TCLer's Wiki

    proc listns {{parentns ::}} {
        set result [list]
        foreach ns [namespace children $parentns] {
                eval lappend result [listns $ns]
                lappend result $ns
        }
        return $result
    }

When I run it, I get the following output:

% listns
::platform ::activestate::teapot::link ::activestate::teapot ::activestate ::tcl
::clock ::tcl::info ::tcl::dict ::tcl::tm ::tcl::mathop ::tcl::unsupported ::tcl
::mathfunc ::tcl::chan ::tcl::string ::tcl
%

So, to get ALL namespaces, you simply need to do this:

set all_namespaces [concat [listns] "::"]


来源:https://stackoverflow.com/questions/10833761/how-do-you-list-all-the-namespaces-in-an-instance-of-tcl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!