TIP #261: Return Imported Commands from [namespace import]

Title:Return Imported Commands from [namespace import]
Version:$Revision: 1.7 $
Authors: Martin Lemburg <martin dot lemburg at gmx dot net>
dgp at users dot sf dot net
Created:Tuesday, 20 December 2005


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 [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, [2], and updated patches will be attached to the same Tracker report.


This document has been placed in the public domain.

Powered by Tcl[Index] [History] [HTML Format] [Source Format] [LaTeX Format] [Text Format] [XML Format] [*roff Format (experimental)] [RTF Format (experimental)]

TIP AutoGenerator - written by Donal K. Fellows