TIP 261: Return Imported Commands from [namespace import]

Author:         Martin Lemburg <[email protected]>
Author:         <[email protected]>
State:          Final
Type:           Project
Vote:           Done
Created:        20-Dec-2005
Tcl-Version:    8.5
Tcl-Ticket:     1437008


This TIP describes a mechanism for easily finding out the list of commands in the current namespace that have been imported from other namespaces.


While writing a profiling and introspection module for our C++/Tcl application, I searched for ways to query all the exported and imported commands of a namespace.

Although I found the introspection functionality for discovering all exported commands of a namespace using namespace export in the exporting namespace, I found no way to query all imported commands inside the importing namespace.

The documentation of namespace import said nothing about the behaviour, if no arguments were given, and testing namespace import without arguments resulted in nothing, in a no-op.

Prompted by this, I started a thread in news:comp.lang.tcl which goes into more detail http://groups.google.com/group/comp.lang.tcl/browse_frm/thread/9fb246cf65aba54f?tvc=1 .

What seems to be more logical to me would be to change the no-op behaviour of namespace import to be comparable to namespace export, and return all imported commands inside the namespace namespace import is executed in.

As an example...


The only consequence I know is, that old scripts using the no-op namespace import suddenly will return a list, probably filled with names of imported commands. That's all.

Because of the fact, that namespace import never returned values, no script should really break, thus no script should require values from this command.

Proposed Change

The result of namespace import without arguments shall be a list of all commands that have been imported into the current namespace. Each command in the list will be the simple name by which the command is known in the current namespace. This format for the returned value is most useful because it composes well with namespace forget. To remove all imported commands from a namespace, use the command

 namespace forget {*}[namespace import]


A patch implementing an earlier draft is available, http://sf.net/tracker/?func=detail&aid=1437008&group_id=10894&atid=310894 , and updated patches will be attached to the same Tracker report.


This document has been placed in the public domain.