Version 2 of How would I reuse my own Tcl code

Updated 1999-11-06 06:07:57

Purpose: describe the various methods available within Tcl for code reuse.

Cut/copy and paste
user maintains a series of text files containing tcl code and then just copies the text when needed.
source
tcl has a command called source which reads a file, treating the contents just as if they were a part of the original file.
load
tcl has a command called load which is used to attach a dynamically loadable object extension to the current library.
packages
See Will Duquette's "Guide to Success with Namespaces and Packages" at http://www.cogent.net/~duquette/tcl/namespaces.html .
unknown
tcl has a command called unknown which is invoked whenever the tcl interpreter is unable to determine a particular command. unknown does some processing and can provide dynamic sourcing of functions. Details go here. See Radical Language Modification for examples how to deal with the unknown.
exec
exec is a tcl command used to invoke a stand alone command. This command can be written in any language supported by the system. Cameron Laird wrote a nice explanation of some of the common questions about exec on comp.lang.tcl a while ago - see http://x8.dejanews.com/getdoc.xp?AN=389920667 for the article.
pipe
tcl supports, in the open command, the ability to open an input and/or output pipeline to another process, which is started in a manner similar to the exec command.

I hope people stopping by this page will update the above descriptions to fill in a lot of the details (where does pkgIndex, tclIndex come in - what other options are available, etc.).