How to use and manage Tcl packages.
Teapot: A package distribution system, for ActiveState::ActiveTcl
In the most elementary case, using a package is a matter of directly employing the load or source command to make the code in some file available to Tcl. This can be seen in the following examples:
Typically, however, packages are distributed such that they can be loaded via the package command.
LV Another common encounter is getting "can't find" and the cause is that the directory in which it was installed isn't on $auto_path , or perhaps the pkgIndex.tcl contains code that just doesn't work. In fact, I've seen cases where syntax code in one package's pkgIndex.tcl caused tcl problems when some other package was required....
Where does the package command find the packages it seeks?:
Building an extension for Tcl under Mac OS X
proc packages {} { # returns the list of presently loaded packages set res {} foreach i [package names] { if {[string length [package provide $i]]} { lappend res $i } } set res } ;# RS
LV Is there a way to modify this packages proc so that it also reports the version of the package that was loaded?
Lars H: Yes, simply change the
lappend res $i
line to
lappend res $i [package provide $i]
RS 2006-01-29: Here's a package version retriever that returns a list, which can be put into a dict or array:
proc packages {{pattern *}} { catch {package require ""} set res {} foreach p [lsort [package names]] { if [string match $pattern $p] { lappend res $p [package versions $p] } } set res }
Incidentally, packages Tcl and ActiveTcl report {} at package versions, seen on 8.4.5 and 8.4.12. At least the former could do the same as what info patchlevel does... Tk says 8.4 at least, but there are many precedents of packaging reporting 3-part version numbers, Mk4tcl even does four: 2.4.9.2. Test:
% foreach {p v} [packages T*] {puts "$p : $v"} Tcl : TclScript : 1.0 Tclx : 8.4 Tk : 8.4 Tkhtml : 2.0 Tktable : 2.8 Tkx : 8.3 Trf : 2.1
See also Tcl modules for possibly new alternatives to packages. Then there is kitten, which is an example of storing packages in a single starkit which is easier to ship around.
package equivalences: jcs: a page to sort out issues regarding packages which need to co-exist, such as binaries with a fallback to a pure Tcl implementation.