Simple question, TCL gives me "premature end of expression" because the last param of the ternary expression is an empty string. If it is anything else then it works ok. Can I use an empty string here?
set y 5
set x [expr ($y > 1) ? 1 : ""]
You should always give expr a single, complete expression, wrapped in braces, as argument. This avoids a whole slew of problems, including this one.
expr {$y > 1 ? 1 : ""}
The problem is that expr concatenates its arguments to get an expression. The invocation concat $y > 1 ? 1 : "" gives the string "5 > 1 ? 1 : ", which can't be parsed by expr.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With