my_question
my_question

Reputation: 3235

Logical not operator

Coming from C/C++ land, I am wondering why the following does not work:

set a 111
if {! $a eq {} } {
  puts hi
}

I know if I change the 2nd line to if { $a ne {} } { then it is fine, but cannot wrap my head around why "!" does not work.

Upvotes: 4

Views: 6592

Answers (1)

Peter Pei Guo
Peter Pei Guo

Reputation: 7870

This is because in Tcl, ! has a higher precedence than ne, so it is evaluated first.

You can check out this link for a complete list of Tcl operator precedence.

Upvotes: 7

Related Questions