2

Can anyone Help me in understanding "package forget" command in TCL .

The TCL manual says that

package forget ?package package ...?
Removes all information about each specified package from this interpreter, including information provided by both package ifneeded and package provide.

As per my understanding after executing the package forget command on a perticular package the commands those are available in that package should not be executed.

Is it like that ?

And also please explain the package unknown command ?

Johannes Kuhn
  • 14,778
  • 4
  • 49
  • 73
  • I just ran a test on 8.4 and **package forget** isn't really forgetting; though, the command did remove the entry from the list returned by **package names**. I can still load and call on commands belonging to a package that was allegedly forgotten. What version are you working with? – bvj Nov 28 '13 at 08:04

1 Answers1

3

The Tcl package mechanism is simple:

When you do package require SomePackage then Tcl will look if it knows something about that package.

  • If it is already loaded (an earlier call to package provide) it will just return the version number.
  • If it is not yet loaded but it knows how to load it (by a previous call to package ifneeded) it will execute that script, does some checks (the package should be loaded, versions must match...) and return the version.
  • If it does know nothing about the package, it will execute package unknown which knows how it can find packages and calls package ifneeded for each found package.

A package forget will just wipe out any information that an package provide and a package ifneeded supplied. The actual commands of that package are not removed.

Johannes Kuhn
  • 14,778
  • 4
  • 49
  • 73
  • Where we can find this "package unknown" related configuration ? Can we cutomize it ? – user2720323 Nov 28 '13 at 09:28
  • Sure. A part of it is in a file called tm.tcl, the other part is in package.tcl. Just exectue `package unknown` to see what command is called when a package is not found. – Johannes Kuhn Nov 28 '13 at 09:30
  • Or, just set `package unknown` to your own handler cmd: `proc ::MyPkgUnknownHandler {pkg version} {;}; package unknown ::MyPkgUnknownHandler` ... This new command will be called upon `package req foo`, also after having forgotten `foo`. – mrcalvin Jul 04 '18 at 07:31