Updated 2016-05-22 11:01:55 by pooryorick

tclPkgUnknown, defined in package.tcl, is the default handler for package when it doesn't know how to load a requested package.

Description  edit

When package require fails, tclPkgUnknown, the default handler for unknown packages, scans directories and their immediate subdirectories in $auto_path, and sources any pkgIndex.tcl files found. During this process, it recognizes and keeps up with changes to $auto_path, as for example when the pkgIndex.tcl files for tcllib and tklib each adds its own directory in order to get its immediate subdirectories scanned.

The design feature of keeping up dynamically with changes made to $auto_path, along with the requirements that each pkgIndex.tcl is read at least once and that items occurring earlier in $auto_path take precedence over later items, lead to an implementation strategy in which the contents of $auto_path are processed from the end to the beginning. Because of this, when a particular value occurs multiple times in $auto_path the position of the last occurrence of the value determines its precedence. Thus, to make sure that a value added to the beginning of $auto_path really takes precedence, first remove any occurrences of that value:
while {[set i [lsearch -exact $auto_path $mydir]] >= 0} {
    set auto_path [lreplace $auto_path $i $i]
}
set auto_path [linsert $auto_path 0 $mydir]

  Obsolete bugs

NB a recent (2006-2007) bug for users of OpenCascade on Windows (which uses Tcl to drive its test harness and other uses) is that if you have 8.4.14 installed and OpenCascade 6.1 then the command:
package require BWidgets

replies:
tclPkgUnknown name version ?exact?

This can be cured by renaming the directory C:\OpenCASCADE6.1.0\3rdparty\win32\tcltk to C:\OpenCASCADE6.1.0\3rdparty\win32\tcltkz (or any other name that is not in the path command).

Suggests that there are 2 versions of tclPkgUnknown in the system with different calling conventions.

MHo: What's this?:
D:\Home\Arbeit1\pgm\tcl\usr\Tst\execx2\test>tclkitsh execx2test.tcl
invalid command name "tclPkgUnknown"
while executing
"tclPkgUnknown execx2 0.1"
("package unknown" script)
invoked from within
"package require execx2 0.1"
invoked from within
"puts [package require execx2 0.1]"
(file "execx2test.tcl" line 8)
D:\Home\Arbeit1\pgm\tcl\usr\Tst\execx2\test>tclkitsh
% info patch
8.4.19
%

This is not the case if I call tclsh 8.5.7 from ActiveState…