OpenOCD website have good resource for learning Tcl. They used Jim Tcl internally for the project.
http://openocd.org/doc/html/Tcl-Crash-Course.html
Here is Tcl rules according to the course.
24.1 Tcl Rule #1
There is a famous joke, it goes like this:
- Rule #1: The wife is always correct
- Rule #2: If you think otherwise, See Rule #1
The Tcl equal is this:
- Rule #1: Everything is a string
- Rule #2: If you think otherwise, See Rule #1
As in the famous joke, the consequences of Rule #1 are profound. Once you understand Rule #1, you will understand Tcl.
24.2 Tcl Rule #1b
There is a second pair of rules.
- Rule #1: Control flow does not exist. Only commands
For example: the classic FOR loop or IF statement is not a control flow item, they are commands, there is no such thing as control flow in Tcl. - Rule #2: If you think otherwise, See Rule #1
Actually what happens is this: There are commands that by convention, act like control flow key words in other languages. One of those commands is the word “for”, another command is “if”.
24.3 Per Rule #1 – All Results are strings
Every Tcl command results in a string. The word “result” is used deliberately. No result is just an empty string. Remember: Rule #1 – Everything is a string