Exercises, examples and other material relating to training module T213. This topic is presented on public courses
Learning to program in Tcl,
Tcl Programming,
Tcl Programming
As your code grows, you'll want to divide it into series of modules. These are known as packages in Tcl. You'll also want to use a separate namespace so that procedure names in one package don't conflict with the same procedure name in another. Libraries allow you to load code in C as well as Tcl into your interpreter.
Articles and tips on this subject | updated |
4522 | Loading packages in your Tcl program In Tcl, extra bundles of code can be loaded from packages which are files of more ... brought in with package require from a folder that's listed in the auto_path variable.
Packages are defined with a package provide in the source code of the package which must be indexed in a file called pkgIndex.tcl. ... | 2015-10-09 |
3417 | What is a namespace and why do we need them? We name variables. We do it so that we can identify specific pieces of data by a key, rether than have to give some longer sort of identification description when referring to them. We don't refer to "the patriarch of the household" = we refer to Zeb. And we refer to Esther, John and Olivia, Jason ... | 2011-09-03 |
3418 | Tcl packages, pkg_mkIndex, pkgIndex.tcl -what are they and why use them. In the previous article [here], I wrote about namespaces and how - as our program grows - we need to keep named pieces of code and globally accessible variable in their own groups. And we do so using a structure that's very much like family names and forenames. As our program grows, we also need to ... | 2011-09-03 |
3066 | Separating groups of variables into namespaces If your program's going to grow in size beyond a certain point, you'll need to use some sort of namespace or package to segment global names into different groupings - moving from a single name to a forename / surname type system, if you like to think of it that way.
In C++, it's namespaces - see [here] ... | 2010-12-04 |
1529 | Tcl - learning how to use namespaces, packages and libraries together Tcl supports both packages (which allow code to be loaded from libraries at run time) and namespaces (which allow for procs and variables to be grouped together to allow you to avoid conflicts as you use code from lots of different sources). Strictly speaking, the two sets of facilities are independent ... | 2008-02-02 |
1339 | Packages and Namespaces are like Suitcases and Aircraft Are Suitcases and Aircraft the same things? No, clearly they're not, but you'll often use them in close assocoation with one another. When I was in Albany, New York State, the other week ... I travelled there from Melksham with a suitcase of luggage, and I used an Aircraft for my journey. Taking ... | 2007-09-11 |
146 | example of Tcl namespaces and packages Packages in Tcl allow you to define a file of code that's going to be loaded as required at run time. Namespaces allow you to define a new set of variable and proc names that doesn't conflict with the variable and proc names in your main program - rather like giving all the variable and procs in part ... | 2006-06-05 |
Examples from our training material
2wice | Using a package that contains a namespace |
dinpack | Using packages and namespaces together |
doubler.tcl | define a package to contain a namespace |
gpack.tcl | package goose - goes with dinpack |
legals.tcl | Definition of a package |
nex | packages with and without namespace |
ns_exim | Namespace export and import |
ns_no | shows how variables are lost between proc calls |
ns_up | Variables saved between proc calls in the next code level up |
ns_y2 | Counting proc calls using a namespace - shorter example |
ns_yes | Saving variables in a namespace |
nsp | setting up and using a namespace |
nsq | Adding a package to a namespace |
packs | Loading a package |
rules.tcl | Definition of a package with namespace |
show.tcl | Defining a package |
tabby.tcl | a namespace wrapped in a package |
toes.tcl | Package to go with twice demo |
tpack.tcl | package chicken - part of dinpack demo |
twice | Using a package - without namespaces |
updown | uplevel - performed in calling code variable space |
Pictures
Public Tcl course
Background information
Some modules are
available for download as a sample of our material or under an
Open Training Notes License for free download from
[here].
Topics covered in this module
The load command.
Startup files.
Startup files - tcl.
Startup files - expect.
Packages.
Loading packages.
Writing your own package.
Using variables across procs and packages.
Recap on using variables between procs.
Namespaces.
Nesting of namespaces.
Exporting and importing.
Packages and namespaces.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our
Listing and schedule page.
Well House Consultants specialise in training courses in
Tcl/Tk, Expect,
Ruby,
Lua,
Python,
Perl,
PHP, and
MySQL. We run
Private Courses throughout the UK (and beyond for longer courses), and
Public Courses at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if
you live in a different
country or continent to us.
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre.