Hacker News new | ask | show | jobs
by ThenAsNow 1223 days ago
> The most horrific thing I discovered about tcl is that curly braces within comments can affect flow control.

This is not true. Once Tcl sees a valid comment, the rest of the line up to the newline is treated as a comment. An odd number of trailing backslashes suppress the newline for interpretation purposes. Within the comment you can use braces or whatever without affecting control flow.

See: https://wiki.tcl-lang.org/page/comment

2 comments

Yes, according to the documentation, braces in comments should be ignored.

However, the parser is confused by unbalanced braces in comments.

Here's a classic case that turns up occasionally during development:

  proc asdf { args } {
    # if { first draft complex condition } {
    if { final simplified condition } {
      do something
    } else {
      do something else
    }
  }
Sourcing a file with the above comment inside the proc will produce:

  missing close-brace: possible unbalanced brace in comment
It is effectively an issue, see https://wiki.tcl-lang.org/page/Why+can+I+not+place+unmatched... If it's a comment in a proc with an unbalanced brace, it parses differently. That's not intuitive or sane IMHO.