Main Content

What does Tcl do if you try to run a command that is not defined?

Archive - Originally posted on "The Horse's Mouth" - 2015-10-10 19:48:15 - Graham Ellis

In Tcl, if a command doesn't exist within the loaded code the interpretter will look through the commands that can be loaded vis package ifneeded, and failing that will call the unknown proc. And there's nothing to stop you defining unknown for yourself, as I did as a demonstration on Friday afternoon on the Learning to program in Tcl course. Example source code [here]

This example also shows a loop in which a whole load of proces is defined, using names in a variable for the name of the command. Yu may think this is a bit of an odd thing to do, but in effect it's what Tk does as it defines commands for each widget, and also what ITcl ([incr-Tcl]) does for its objects - it's just not a common think in a little demo program.

Finally, the example shows how yo accesss shell environment variables via the array env