Building reusable libraries - packages and namespaces

Table of Contents

Building reusable libraries - packages and namespaces
Using packages
Creating a package
Namespaces
Using namespace with packages
Example
Ensembles

Building reusable libraries - packages and namespaces

The previous lesson showed how the source command can be used to separate a program into multiple files, each responsible for a different area of functionality. This is a simple and useful technique for achieving modularity. However, there are a number of drawbacks to using the source command directly. Tcl provides a more powerful mechanism for handling reusable units of code called packages. A package is simply a bundle of files implementing some functionality, along with a name that identifies the package, and a version number that allows multiple versions of the same package to be present. A package can be a collection of Tcl scripts, or a binary library, or a combination of both. Binary libraries are not discussed in this tutorial.