Version 3 of package require

Updated 2003-11-20 17:29:04

package require ?-exact? package ?version?

This command is typically invoked by Tcl code that wishes to use a particular version of a particular package. The arguments indicate which package is wanted, and the command ensures that a suitable version of the package is loaded into the interpreter. If the command succeeds, it returns the version number that is loaded; otherwise it generates an error. If both the -exact switch and the version argument are specified then only the given version is acceptable. If -exact is omitted but version is specified, then versions later than version are also acceptable as long as they have the same major version number as version. If both -exact and version are omitted then any version whatsoever is acceptable. If a version of package has already been provided (by invoking the package provide command), then its version number must satisfy the criteria given by -exact and version and the command returns immediately. Otherwise, the command searches the database of information provided by previous package ifneeded commands to see if an acceptable version of the package is available. If so, the script for the highest acceptable version number is evaluated in the global namespace; it must do whatever is necessary to load the package, including calling package provide for the package. If the package ifneeded database does not contain an acceptable version of the package and a package unknown command has been specified for the interpreter then that command is evaluated in the global namespace; when it completes, Tcl checks again to see if the package is now provided or if there is a package ifneeded script for it. If all of these steps fail to provide an acceptable version of the package, then the command returns an error.


See also:


escargo 20 Nov 2003 - Is there any easy way to tell where a package is loaded from? am looking at code that does a package require snit 0.9 and the value returned is 0.82, and it is not at all obvious where that value is coming from.

DGP Use package ifneeded to discover what script was used to load a package.

    package ifneeded snit [package provide snit]

That will return the script that loaded snit, which likely looks something like:

    source /absolute/path/to/snit/snit.tcl

Is that what you were asking?


Tcl syntax help - Category Command