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

introspection, namespaces, tcl

Solution

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] "::"]

Problem

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

Original source