if
or proc
that they belong to, and forces you to use the atrocious "} else {"
style.That's appalling, but get this: it also requires a space to the right of the close-brace "}". That's just plain stupid.
Compounding the problem, the error message isn't something like "a space is required after a close-brace". Oh no. It says "extra characters after close-brace". And if the body of your
if
is very long, like this:if {$tcl_is_stupid} { # ... many lines of code ... # Next line is the error }else{ i_eat_my_hat }
then the error message is truncated so that you only see the part of the command that isn't broken, along with the line number of the "if", not the offending "else". As icing on the cake, in the case I was trying to help someone figure out, the error was at the top of one of Tcl's Icelandic Saga stacktraces, and the line number reported to be in error was with respect to the
proc
it was in, not the file.Thankfully, Google led me to the answer, because Tcl sure didn't. I love the subtitle of that Tcl wiki page: Purpose: to discuss one of the few 'gotchas' in Tcl. Ha! What a crock!
13 comments:
Thank you for this post, saved me from eating my hat =)
saved my day. I don't know who's idea it was, but this is ridiculous
Thanks for the explanation. Helped me a lot
Thanks for the help. Tcl is nice for prototyping GUIs but WOW! That community really needs to fix its documentation!
Thanks for the help...
My hat is intact too. Thanks to you!
This is how I want all blogs to be :-) Short piece of information that saved my day. Thanks.
Thank you
Tcl is a nightmare. You are the bedside light.
Have you run into the "braces in comments are syntactically significant" SNAFU yet?
This doesn't compile:
proc hello {
# I'd like to put an unmatched { in my comment
puts "Hello!"
}
Ha ha! Thanks for pointing that one out. I may have to make a new post just for that one.
What I love is, if you change your open brace for a close brace, you get a message that doesn't begin to tell you the problem:
wrong # args: should be "proc name args body"
At least with the open brace I get:
missing close-brace: possible unbalanced brace in comment
They're also syntactically significant in strings.
proc goodbye {} {
puts "Sod off, { tcl!"
}
PS. Sorry, there was a syntax error in my previous post. Should have been an empty parameter list {} after between "hello" and the opening brace. But anyway.
I'm an ASIC verification engineer, and having to use Tcl makes me pine for the relative sanity of SystemVerilog. And that's bloody scary.
amazing!!!!
well I still haven't found the "extra" characters after my braces in my very long ifelse chain and I am about to kill myself
Post a Comment