0
votes

I am reading "Tcl/Tk: A developer's guide", in chapter 3.1, it has such bad example:

if {$x > 2} {
     set greater true
}

The book says this code is wrong syntax because "No space between test and body left brace" and will get error message:

Error Message: invalid command name "}"

I tried it in tclsh, it works fine. Also I do not think "{$x" is wrong, "{" is at the start position of a word, so whatever stuff till the matching "}" is enclosed.

Do you see anything wrong?

1
my guess is that you didn't copy the code from the book correct. Doesn't it say: if {$x > 2}{set greater true} i.e.: a }{ without a space in between? Please check that first. - klas2iop

1 Answers

1
votes

In the book, it is given without spaces only.

enter image description here

Running this we will the get the following errors.

% if {$x > 2}{
extra characters after close-brace
%      set greater true
true
% }
invalid command name "}"
%