Tcl Crash Course

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:

  1. Rule #1: The wife is always correct
  2. Rule #2: If you think otherwise, See Rule #1

The Tcl equal is this:

  1. Rule #1: Everything is a string
  2. 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.

  1. 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.
  2. 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

Leave a Reply

Your email address will not be published. Required fields are marked *