TIP 722: Return loaded packages by ”package present”

Login
 Author:         Christian Werner <[email protected]>
 Tcl-Version:    9.1
 State:          Draft
 Type:           Project
 Created:        19-May-2025
 Keywords:       Tcl,package
 TCL-Branch:     tip-722-loaded-package-list

Abstract

This TIP proposes to improve the package present subcommand such that it can be used to return a list of all currently loaded packages.

Rationale

Although there is a package names subcommand which returns a list of all currently available packages there's no equivalent to retrieve the list of currently loaded packages. However, the latter can be of use e.g. to build a software bill of materials of an application or to help in generating a package dependency graph.

Specification

package present

Return a list of currently loaded packages.

An example session of a fresh compiled tclsh:

% package present
tcl::zlib tcl::oo TclOO tcl::tommath tcl Tcl

Background

For package present without any further arguments (which currently generates an error message) the implementation of package names is borrowed but its selection clause while iterating over the package hash table is changed to add package names to the result list for which a version is known (which means that the package has been loaded).

Implementation

In branch tip-722-loaded-package-list

Copyright

This document has been placed in the public domain.

OSZAR »