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

橙三吉。 提交于 2019-12-06 02:53:48

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