Version 9 of package names

Updated 2008-06-05 19:14:22 by LV

package names

Returns a list of the names of all packages in the interpreter for which a version has been provided (via package provide) or for which a package ifneeded script is available. The order of elements in the list is arbitrary.


package names will only deliver all available packages if it has searched all package indices before. To force this, do a dummy package require before:

 catch {package require nonexistentName}
 package names

DGP - To be more precise, [package names] returns a list of all the package names that are already known to the [package] command. That is not the same as all the names that could become known by operation of the [package unknown] callback.

The default [package unknown] callback is [tclPkgUnknown] and it is that default callback that exhibits the behavior described above -- after one run, all installed package names are known. The [package unknown] interface does not require that behavior, and other callbacks may not (IMHO, should not) implement it.

Lars H: Feeling slightly Cantorian, I'd propose the following for a foolproof (never loading a package, even if it's got a bizarre name) method of listing all package names:

  proc all_package_names {} {
     set res ""
     while {$res ne [set res [package names]]} {
        if {[package unknown] eq ""} then {break}
        uplevel #0 [package unknown] [list $res+1 ""]
     }
     return $res
  }

The idea is that "[package names]+1" cannot be the name of a package known to the package database, so telling package unknown to search for it will force some additional data to be entered (even with a very lazy package unknown handler) as long as there is any.


LV 2008 Jun 05 Did something change with the way package names, etc. worked in Tcl 8.5? The reason I ask is this. Under Tcl 8.4, when I ran this routine, I would get over 400 names returning in ActiveTcl. Under ActiveTcl 8.5, I am only seeing 100. Now, I know that ActiveTcl, out of the box, comes with fewer packages. But what I am seeing is different. For instance, most of the tcllib packages are displaying differently now. I have tcllib installed in both local teapots. I can start up both tclsh's , do a package require math::bigfloat and get it.

However, the above code, when run against tcl 8.4.19, shows all the math::bigfloat, etc. routines, but when run against activetcl 8.5.2, the routine only shows math, with none of the ::other names. They are there in AT 8.5 - just not showing up. Even at the top level - things like md5 shows when I run the above code in AT 8.4 but not AT 8.5.

It seems as if somehow things are just not quite the same.


See also: