Libraries
By default, the unknown command tries to find procedure definitions in a library. A library is simply a file that contain procedure definitions. Libraries can be explicitly read using the source command. However, it is possible to prepare an index file which describes the library contents in such a way that Tcl knows which library to load based on the command name. Once a library is loaded, the unknown command calls the new procedure just defined. After the procedure completes, unknown completes and it appears as if the procedure had been defined all along.
As an example, one of Tcl’s default libraries defines the parray procedure. parray prints out the contents of an array. It is a parameterized version of the code on page 51. The info command shows that parray is not defined before it is invoked, but it is defined afterwards.
tclsh>info command parraytclsh>parray colorcolor(pavement) = black color(snow) = white tclsh>info command parrayparray
You can add procedures to the libraries or create new libraries. See the Tcl reference material for more information on using libraries.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access