Tcl - learning how to use namespaces, packages and libraries together
Archive - Originally posted on "The Horse's Mouth" - 2008-02-02 09:16:42 - Graham EllisTcl 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 but in practice they're used together, with the name of the package and the name of the namespace usually being the same.
Having covered both topics independently on yesterday's course, I went on to write a short new example that shows how they work together and I've added the course code of that example to our web site - this is an example that shows you a lot in a few lines!
Source code of the main program - here
Source code of the packages it loads - here and here
Sample output:
Dorothy:jtc grahamellis$ tclsh dinpack
Copyright Well House Consultants, 2008
Copyright Well House Consultants, 2008
You need a 11.0kgs bird if it's a chicken
You need a 13.9kgs bird if it's a goose
You need a 13.9kgs bird if it's imported
Dorothy:jtc grahamellis$
This subject covered on our Public Tcl Course. There's a lot to cover on that course, so it's quite a short section. Also covered on private courses at our centre which are tailored to meet your needs (Full list of modules on Tcl). For larger groups, we can also run courses at you own office