tcl Expressions Calling a Tcl command from an expression


Example

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 if you find yourself calling expr itself, stop! and think whether you really need that extra call. You can usually do just fine by putting the inner expression in parentheses.