TCL Expressions
Tcl allows several types of expressions, including mathematical expressions, and relational expressions. Tcl expressions are usually evaluated using
the expr command, as illustrated in the examples below.
Example 2.1:
expr 0 == 1
Output: 0
Example 2.2:
expr 1 == 1
Output: 1
Examples 2.1 and 2.2 illustrate the use of relational expressions with the expr command. The first
expression evaluates to 0 (false) since 0 does not equal 1, whereas the second expression evalutates to 1 (true), since, obviously, 1 does equal
1. The relational operator "==" is used to do the comparison.
Example 2.3:
expr 4 + 5
Output: 9
Example 2.3 shows how to use the expr statement to evaluate an arithmetic expression. Here the result is simply
the sum of 4 and 5. Tcl offers a rich set of arithmetic and relational operators, each of which is described in the expr manual page.
Example 2.4:
expr sin(2)
Output: 0.909297
This example shows that the expr statement can be used to evaluate the result of a mathematical function,
in this case, the sine of an angle. Tcl offers many such mathematical functions, also described on the expr manual page.