如何列出在tclsh实例中加载的所有命名空间?
Chenz
Chenz
proc listns {{parentns ::}} {
set result [list]
foreach ns [namespace children $parentns] {
eval lappend result [listns $ns]
lappend result $ns
}
return $result
}
% 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
%
set all_namespaces [concat [listns] "::"]
lappend result {*}[listns $ns] $ns
可以改进(并且只需要广泛部署的 8.5 版本)。 - Donal Fellows