Tutorial by Examples

It is a good practice to provide expression string arguments as braced strings. The heading "Double Substitution" outlines important reasons behind the same. The expr command evaluates an operator-based expression string to calculate a value. This string is constructed from the arguments ...
set myVariable [expr { $myVariable * 17 }] This shows how you can use a simple expression to update a variable. The expr command does not update the variable for you; you need to take its result and write it to the variable with set. Note that newlines are not important in the little language un...
Sometimes you need to call a Tcl command from your expression. For example, supposing you need the length of a string in it. To do that, you just use a [...] sequence in the expression: set halfTheStringLength [expr { [string length $theString] / 2 }] You can call any Tcl command this way, but i...
In Tcl itself, a string consisting of a single word does not need to be quoted. In the language of expression strings that expr evaluates, all operands must have an identifiable type. Numeric operands are written without any decoration: expr {455682 / 1.96e4} So are boolean constants: expr {tr...

Page 1 of 1