Chapter 8

Namespaces, Packages and Modules

The namespace and package commands implement two different concepts that work together to make it easier to write reusable, modular, easily maintained code. The namespace command provides encapsulation support for developing modular code. The package command and modules provide tools for organizing collections of code into libraries.

The namespace command collects persistent data and procedure names in a private scope where they will not interact with other data or procedure names. This lets you load new procedures without cluttering the global space (avoiding name collisions) and protects private data from unintentional corruption.

The package command groups a set of procedures that may be in separate ...

Get Tcl/Tk, 3rd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.